我有一条路线
'服务器已接收:'+ exchange.getIn()。getBody(String.class)
我想使用一些Java客户端将数据发送到此套接字。我该怎么办?
答案 0 :(得分:0)
“收到的服务器:” + exchange.getIn()。getBody(String.class)不是骆驼路线,它更多是打印正文内容的处理器。您需要定义一个CamelContext,使用自定义处理器添加路由
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
System.out.println("Server received: " + body);
}
})
}
});
ProducerTemplate template = context.createProducerTemplate();
context.start();
template.sendBody("direct:start", "Hello World");