我可以成功读取文件并使用Camel Netty通过UDP发送内容,但前提是我在通过UDP发送之前修改处理器中的消息内容。
我有一个简单的类来演示,它有两个驼峰路线:
将文件写入发件箱似乎总是有效(暗示我认为骆驼布线没问题),但是如果我手动更新消息内容,则仅通过UDP发送似乎有效。代码如下,我尝试了以下内容:
更新
代码:
public class App {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file://inbox?noop=true")
// .process(new Processor() {
// public void process(Exchange exchange) {
// Message in = exchange.getIn();
// in.setBody("blah");
// in.setBody(in.getBody());
// System.out.println("Read [" + in + "] from file");
// }
// })
.to("file://outbox")
.to("netty:udp://localhost:9999/");
}
});
context.addRoutes(new RouteBuilder() {
public void configure() {
from("netty:udp://localhost:9999/")
.process(new Processor() {
public void process(Exchange exchange) {
Message in = exchange.getIn();
System.out.println("Got [" + in.getBody() + "] over UDP");
}
});
}
});
context.start();
Thread.sleep(5000);
context.stop();
}
}