JAVA DSL を使用する単純なキャメル MINA サーバーがあり、ここに記載されている例のように実行しています。
「mina:tcp://localhost:9991」(別名 MyApp_B) でホストされるサンプル アプリケーションを作成しようとしています。このアプリケーションは、「mina:tcp://localhost:9990」(別名 MyApp_A) でホストされるサーバーに非常に単純なメッセージを送信します。 )。
ヘッダーに文字列 (「Hello World!」) を含み、本文にアドレスを含む単純なメッセージを送信したいと考えています。
public class MyApp_B extends Main{
public static final String MINA_HOST = "mina:tcp://localhost:9991";
public static void main(String... args) throws Exception {
MyApp_B main = new MyApp_B();
main.enableHangupSupport();
main.addRouteBuilder(
new RouteBuilder(){
@Override
public void configure() throws Exception {
from("direct:start")
.setHeader("order", constant("Hello World!"))
.setBody(constant(MINA_HOST))
.to("mina:tcp://localhost:9990");
}
}
);
System.out.println("Starting Camel MyApp_B. Use ctrl + c to terminate the JVM.\n");
main.run();
}
}
public class MainApp_A {
public static void main(String... args) throws Exception {
Main main = new Main();
main.enableHangupSupport();
main.addRouteBuilder(new RouteBuilder(){
@Override
public void configure() throws Exception {
from("mina:tcp://localhost:9990").bean(MyRecipientListBean.class,
"updateServers").to("direct:debug");
from("direct:debug").process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Received order: " +
exchange.getIn().getBody());
}
});
}
});
main.run(args);
}
}
MyApp_A で使用される Bean:
public class MyRecipientListBean {
public final static String REMOVE_SERVER = "remove";
public final static String ADD_SERVER = "add";
private Set<String> servers = new HashSet<String>();
public void updateServers(@Body String serverURI,
@Header("order") String order){
System.out.println("===============================================\n");
System.out.println("Received " + order + "request from server " + serverURI + "\n");
System.out.println("===============================================\n");
if(order.equals(ADD_SERVER))
servers.add(serverURI);
else if(order.equals(REMOVE_SERVER))
servers.remove(serverURI);
}
}
このコードを実行しましたが、反対側のサーバーは何も受信していないようです。したがって、2 つの質問があります。
- 私は何か間違ったことをしていますか?
- Camel を使用して簡単なメッセージを送信するより良い方法はありますか?