0

我们有一个场景,应该根据消息内容和不同的条件进行消息路由。我们将条件存储在数据库中,条件将在运行时由不同的应用程序配置,我们计划将此路由条件保存在路由应用程序可以访问的缓存中。

整个路由应用程序的工作是根据消息和条件确定下一步(队列),并将消息放入正确的队列,以便相关应用程序选择消息并处理它。

有没有简单的方法来实现这个场景而不使用 apache camel 等条件是简单的相等,不相等等检查 XML 消息。

4

2 回答 2

0

You can do these kinds of dynamic routing with the Recipient List EIP of Camel. If the simple conditions like a header value etc are not sufficient, you can use a Java Bean method as Recipient List.

In this method you can access all parts of the message and do whatever you want. If you found out where the message must be sent to, simply return the Camel endpoint URI. For example activemq:queue:myQueue.

The recipient list can also send the (same) message to multiple endpoints if this is a requirement.

于 2020-06-25T06:19:49.683 回答
0

Spring Integration 提供了一个RouterEIP 实现,您可以在其中通过 POJO 方法调用指定自定义逻辑并决定将消息发送到哪个输出通道:https ://docs.spring.io/spring-integration/docs/current/reference/html/ message-routing.html#messaging-routing-chapter

这就是为什么它MessageChannel是框架中的第一类公民之一:您的业务逻辑与路由逻辑无关,您可以在每个通道子流上制作任何复杂的流,而不会影响应用程序中的任何其他内容。

于 2020-06-25T15:58:41.433 回答