Java 8和Apache Camel 2.19.5。我想定义一个路由(使用Spring XML DSL)来完成以下任务:
Fizzbuzz
实例Fizzbuzz
发送到FoobarGenerator
处理器Foobar
消息的exchangeFoobar
,然后同时传递到两个下游处理器:(a) D16处理器和(b) D17处理器6a。Configurator
处理Foobar
并将一些结果存储在DB 6b中。Analyzer
处理Foobar
,然后路由将该实例发送到反序列化程序(返回到字符串中),然后将该字符串发送到另一个AMQ queue这是我到目前为止所知道的:
<route id="fizzbuzz_processor">
<!-- Step 1: Consume Fizzbuzz XML from AMQ -->
<from uri="activemq:fizzbuzzes"/>
<!-- Step 2: Deserialize into Fizzbuzz POJO instance, using XStream -->
<unmarshall ref="xs"/>
<!--
Step 3 + 4: Send to FoobarGenerator processor;
output is a 'Foobar' POJO instance
-->
<to uri="bean:foobarGenerator"/>
<!-- Step 5: Send Foobar to two places at the same time -->
<multicast>
<!-- Step 6a: Foobar goes to Configurator processor -->
<to uri="bean:configurator"/>
<!-- Step 6b: Foobar also goes to Analyzer processor -->
<to uri="bean:analyzer"/>
<!--
AFTER Analyzer, Foobar gets serialized into XML and sent
to another queue
-->
<marshall ref="xs"/>
<to uri="activemq:foobars"/>
</multicast>
</route>
这种设置的问题在于,据我所知,multicasters只能定义为它们将向其发送消息的顶级端点。因此,按照我上面配置的方法,多播将发送消息到:(a) bean:configurator,(b) bean:analyzer,(c) XStream/marshaller,和(d) activemq:fizzbuzzes,而不是同时发送到bean:configurator和bean:analyzer,然后在bean:analyzer之后,编组并发送到。
如何重新配置此路由以执行我想要的操作?
发布于 2019-03-27 09:04:22
事实证明你可以这样做:
<route id="fizzbuzz_processor">
<!-- Step 1: Consume Fizzbuzz XML from AMQ -->
<from uri="activemq:fizzbuzzes"/>
<!-- Step 2: Deserialize into Fizzbuzz POJO instance, using XStream -->
<unmarshall ref="xs"/>
<!--
Step 3 + 4: Send to FoobarGenerator processor;
output is a 'Foobar' POJO instance
-->
<to uri="bean:foobarGenerator"/>
<!-- Step 5: Send Foobar to two places at the same time -->
<multicast parallelProcessing="true">
<!-- Step 6a: Foobar goes to Configurator processor -->
<to uri="bean:configurator"/>
<!-- Step 6b: Foobar also goes to Analyzer processor -->
<to uri="direct:someOtherRoute"/>
</multicast>
</route>
其中direct:someOtherRoute
转到另一条实现我所描述的6b之后的所有内容的路由,而boom您已经同时多播到了这两个“地方”。
发布于 2019-03-22 15:47:01
为什么要使用多播弹性公网EIP?看起来你可以得到同样的结果,或者通过完全删除多播,例如:
<route id="fizzbuzz_processor">
<!-- Step 1: Consume Fizzbuzz XML from AMQ -->
<from uri="activemq:fizzbuzzes"/>
<!-- Step 2: Deserialize into Fizzbuzz POJO instance, using XStream -->
<unmarshall ref="xs"/>
<!--
Step 3 + 4: Send to FoobarGenerator processor;
output is a 'Foobar' POJO instance
-->
<to uri="bean:foobarGenerator"/>
<!-- Step 6a: Foobar goes to Configurator processor -->
<to uri="bean:configurator"/>
<!-- Step 6b: Foobar also goes to Analyzer processor -->
<to uri="bean:analyzer"/>
<marshall ref="xs"/>
<to uri="activemq:foobars"/>
</route>
或者通过将marshal/activemq部分留在多播之外。Camel应该完成多路广播,然后继续执行marshal/to。
https://stackoverflow.com/questions/55268331
复制相似问题