[英]Routing multiple messages to same stream in apache camel
I came up with a scenario where I will create multiple XML messages and set them as part of the Exchange object.我想出了一个场景,我将创建多个 XML 消息并将它们设置为 Exchange 对象的一部分。
In my router how can I route multiple message parts set in the exchange body to the same stream?在我的路由器中,如何将交换正文中设置的多个消息部分路由到同一个流? Basically i have to send two different set of messages as a part of property to a MQ.
基本上,我必须将两组不同的消息作为属性的一部分发送到 MQ。
Processor Code处理器代码
public void process(Exchange exchange) throws Exception {
exchange.setProperty("msg1", xml1);
exchange.setProperty("msg2",xml2);
}
Router Code路由器代码
@Override
public void configure() {
from("solace:q")
.process(aboveProcessor)
..?//code to route both messages as two different messages to same MQ.
}
If there is some other approach I should use, kindly let me know.如果我应该使用其他方法,请告诉我。
Instead of setting Exchange Properties, which are not sent with JMS messages anyway, you could populate a list in your processor, setting the body to be the resultant list:您可以在处理器中填充一个列表,将正文设置为结果列表,而不是设置 Exchange 属性,这些属性无论如何都不会与 JMS 消息一起发送:
public void process(Exchange exchange) throws Exception {
List<Object> list = new ArrayList<Object>();
list.add( xml1 );
list.add( xml2 );
exchange.getIn().setBody( list );
}
and then split the list, before sending to your queue:然后拆分列表,然后发送到您的队列:
from("solace:q")
.process(aboveProcessor)
.split(body())
.to("mq:myQueue");
This assumes you are sending each of your two XML documents to the same queue, and with the same message headers.这假设您将两个 XML 文档中的每一个都发送到同一个队列,并使用相同的消息头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.