骆驼动态路由不转发邮件
问题描述:
我正在基于webservice和jms队列的骆驼动态路由管理器。我有这个以下结构:骆驼动态路由不转发邮件
endpoint:cxf -> jms:queue -> dynamic routing to a jms:queue -> processing
这里是我的路由定义:
@Override
public void configure() throws Exception {
routeDefinition = from(fromEndpoint).routeId(name)
.dynamicRouter(method(DynamicRoutingManager.class, "getRoute")).process(exchange -> {
final List<?> soaList = exchange.getIn().getBody(List.class);
final String type = (String) soaList.get(0);
final String documentNumber = (String) soaList.get(1);
final String productionStepNumber = (String) soaList.get(2);
final String message = (String) soaList.get(3);
final String messageToSend = "Route ID=" + name + ", from=" + fromEndpoint + ", type=" + type
+ ", document number=" + documentNumber + ", production step number" + productionStepNumber
+ ", message=" + message;
LOG.debug("==> message={}", messageToSend);
exchange.getOut().setBody(messageToSend);
}); // .to(DLQ);
}
,在这里我的动态路由管理器(保持简单):
public String getRoute(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
LOG.debug("========> BODY={}", body);
return "jms:topic:urgent_doc1_prod1";
}
路线jms:topic:urgent_doc1_prod1
在运行时定义并运行(在日志中查看)
事实是wh恩我送一个这样的请求(见下文),我收到了超时错误......
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://cxf.apache.org/wsse/handler/helloworld">
<soapenv:Header/>
<soapenv:Body>
<hel:message>
<!--Optional:-->
<type>urgent</type>
<!--Optional:-->
<document_number>1</document_number>
<!--Optional:-->
<production_step_number>1</production_step_number>
<!--Optional:-->
<message>un message</message>
</hel:message>
</soapenv:Body>
</soapenv:Envelope>
因为我觉得我的消息不forwared到第二JMS:队列,所以可以做任何处理...
我做错了什么?
答
使用recipientList
或toD
,如果你想将消息路由到一个动态的目标 - 看到这个常见问题:http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
动态路由器就像是while loop
,保持路由,直到你告诉它停止空/空目的地。请参阅顶部的文档:http://camel.apache.org/dynamic-router.html。而你的例子并没有将它作为硬编码的目标值。
答
其实,这是我的一个误解。我没有在动态路由之后独立地声明“from”路由,所以没有消费者,所以超时。
@Override
public void configure() throws Exception {
from(fromEndpoint).routeId(name + "a").recipientList(method(DynamicRoutingManager.class, "getRoute"));
from(toEndpoint).routeId(name + "b").process(exchange -> {
final List<?> soaList = exchange.getIn().getBody(List.class);
final String type = (String) soaList.get(0);
final Integer documentNumber = (Integer) soaList.get(1);
final Integer productionStepNumber = (Integer) soaList.get(2);
final String message = (String) soaList.get(3);
final String messageToSend = "Route ID=" + name + ", from=" + fromEndpoint + ", type=" + type
+ ", document number=" + documentNumber + ", production step number" + productionStepNumber
+ ", message=" + message;
LOG.debug("==> message={}", messageToSend);
exchange.getOut().setBody(messageToSend);
});
}
使它起作用。
感谢您的回答,但它不起作用。邮件列入'jms:topic:urgent_doc1_prod1',但从未出列并以DLQ结尾.. – ggwtf
我不想问您的问题。您是否正在通过JMS进行某种请求/回复,并希望骆驼在继续之前等待回复消息。 –
我使用用户界面在运行时动态创建路由,动态部分用于根据这些动态路由转发消息(根据请求中定义的选项)。最后,目前,我只想发送一个处理过的消息(包含最初请求的内容) – ggwtf