camel-twilio
componentを使用してApache Camelでテキストメッセージを送信しようとしています。 Twilio APIを使用したことはありません(ネイティブでもApache Camelも使用していないため)、パラメータを正しく取得しているかどうかはわかりません。ここに私が書いた方法があります:Apache Camel:Twilioでテキストメッセージを送信
/**
* Sends a text message to the given recipient's number (parameter to)
*
* @param username:
* Twilio username (email)
* @param password:
* Twilio password (in plain text)
* @param accountSid:
* Twilio account sid (from the dashboard)
* @param from:
* registered phone number (starting with country prefix +XX)
* @param to:
* the recipient's phone number (starting with country prefix +XX)
* @param message:
* the message to be sent (plain text)
* @throws Exception
*/
public static void sendTextMessage(String username, String password, String accountSid, String from, String to,
String message) throws Exception {
String route = String.format("twilio:message/creator?username=%s&password=%s&accountSid=%s&from=%s&to=%s",
username, password, accountSid, from, to);
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:message").to(route);
}
});
context.start();
ProducerTemplate producer = context.createProducerTemplate();
producer.sendBody("direct:message", message);
context.stop();
}
最も重要な行は、方法の最初のルートの作成です。私はJavaDocのに応じてパラメータを指定して、この方法を実行しているとき、私はこのエラーを取得する:
Caused by: org.apache.camel.RuntimeCamelException: Missing properties for creator, need one or more from [pathAccountSid, mediaUrl, messagingServiceSid, body]
だから私は再び私accountSid
を提供し、パラメータmessagingServiceSid
を追加するために考えた:
String route = String.format("twilio:message/creator?username=%s&password=%s&accountSid=%s&from=%s&to=%s&messagingServiceSid=%s",
username, password, accountSid, from, to, accountSid);
私が手このエラーメッセージ:
Caused by: java.lang.IllegalArgumentException: No matching method for message/creator, with arguments [messagingServiceSid, from, to]
私は間違っていますか?
EDIT:
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.20.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-twilio</artifactId>
<version>2.20.1</version>
</dependency>
</dependencies>
EDIT 2:これらは私のMavenの依存関係です。ここだ修正及び方法の作業バージョン:
/**
* Sends a text message to the given recipient's number (parameter to)
*
* @param accountSid:
* Twilio account sid (from the dashboard)
* @param authToken:
* Twilio auth token (from the dashboard)
* @param from:
* registered phone number (starting with country prefix +XX)
* @param to:
* the recipient's phone number (starting with country prefix +XX)
* @param message:
* the message to be sent (plain text)
* @throws Exception
*/
public static void sendTextMessage(String accountSid, String authToken, String from, String to, String message)
throws Exception {
CamelContext context = new DefaultCamelContext();
TwilioComponent twilio = context.getComponent("twilio", TwilioComponent.class);
twilio.getConfiguration().setUsername(accountSid);
twilio.getConfiguration().setPassword(authToken);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:message")
.setHeader("CamelTwilioTo", constant(new PhoneNumber(to)))
.setHeader("CamelTwilioFrom", constant(new PhoneNumber(from)))
.setHeader("CamelTwilioBody", constant(message))
.to("twilio://message/creator");
}
});
context.start();
ProducerTemplate producer = context.createProducerTemplate();
producer.sendBody("direct:message", message);
context.stop();
}
が、それは動作します:
FYI、春ブーツとキャメル-twilioの実施例があります!どうもありがとうございます! –