我如何在不等待该端点的路由被处理的情况下将消息发送到端点(即,我的路由应仅调度该消息并完成)?
最佳答案
您需要使用wireTap或多播。无论指定了什么ExchangePattern,direct:终结点都将为下一步修改Exchange。通过使用此失败的测试,您可以看到:
public class StackOverflowTest extends CamelTestSupport {
private static final String DIRECT_INPUT = "direct:input";
private static final String DIRECT_NO_RETURN = "direct:no.return";
private static final String MOCK_OUTPUT = "mock:output";
private static final String FIRST_STRING = "FIRST";
private static final String SECOND_STRING = "SECOND";
@NotNull
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from(DIRECT_INPUT)
.to(ExchangePattern.InOnly, DIRECT_NO_RETURN)
.to(MOCK_OUTPUT)
.end();
from(DIRECT_NO_RETURN)
.bean(new CreateNewString())
.end();
}
};
}
@Test
public void testShouldNotModifyMessage() throws JsonProcessingException, InterruptedException {
final MockEndpoint myMockEndpoint = getMockEndpoint(MOCK_OUTPUT);
myMockEndpoint.expectedBodiesReceived(FIRST_STRING);
template.sendBody(DIRECT_INPUT, FIRST_STRING);
assertMockEndpointsSatisfied();
}
public static class CreateNewString {
@NotNull
public String handle(@NotNull Object anObject) {
return SECOND_STRING;
}
}
}
现在,如果将以上内容更改为wireTap:
from(DIRECT_INPUT)
.wireTap(DIRECT_NO_RETURN)
.to(MOCK_OUTPUT)
.end();
并且您会看到它按预期工作。您还可以使用多播:
from(DIRECT_INPUT)
.multicast()
.to(DIRECT_NO_RETURN)
.to(MOCK_OUTPUT)
.end();
关于java - Camel : how can i send to an endpoint asynchronously,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11981900/