在骆驼中,说不是所有ENDPOINT
支持INOUT
ExchangePattern
是否正确?
如果是,那么文档的哪一部分告诉哪个端点支持哪个ExchangePattern
或者这是隐含的知识。
最高ENDPOINT
为INOUT
提供支持。
以下是我得出结论的代码示例。
我正在玩camel example-jms-file并将其修改为
queue1 - > queue2 ---> file:// test --->文件:// TEST1
context.addRoutes(new RouteBuilder() {
public void configure() {
from("test-jms:queue:test.queue1")
.process(sleep(1))
.to("test-jms:queue:test.queue2");
from("test-jms:queue:test.queue2")
.process(sleep(2))
.to("file://test");
from("file://test")
.process(sleep(3))
.to("file://test1");
}
private Processor sleep(final int sleepId) {
return new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("Going for sleep sleepid=" + sleepId + ", thread=" + Thread.currentThread().getName());
Thread.sleep(5000l);
System.out.println("Done sleep sleepid=" + sleepId + ", thread=" + Thread.currentThread().getName());
}
};
}
});
然后我使用以下代码将msg发送到队列:
Exchange exchange = new DefaultExchange(context);
exchange.setPattern(ExchangePattern.InOut);
exchange.getIn().setBody("Test Message: 1");
System.out.println("sending msg to queue1");
Exchange send = template.send("test-jms:queue:test.queue1",exchange);
// If queue and file endpoint support INOUT then below line should get printed at last.
System.out.println("received response");
执行以上操作会给出以下回复:
sending msg to queue1
Going for sleep sleepid=1, thread=Camel (camel-1) thread #0 - JmsConsumer[test.queue1]
Done sleep sleepid=1, thread=Camel (camel-1) thread #0 - JmsConsumer[test.queue1]
Going for sleep sleepid=2, thread=Camel (camel-1) thread #1 - JmsConsumer[test.queue2]
Done sleep sleepid=2, thread=Camel (camel-1) thread #1 - JmsConsumer[test.queue2]
received response ## this getting printed here meaning that the file endpoint do not respect the INOUT exchangepattern.
Going for sleep sleepid=3, thread=Camel (camel-1) thread #2 - file://test
Done sleep sleepid=3, thread=Camel (camel-1) thread #2 - file://test
如果我们观察执行输出,我们会看到收到的响应在完成从FILE
ENDPOINT
开始的路线之前打印出来。
这表明文件端点不理解交换是INOUT交换
图形表示:(点击图片放大)