使用收件人列表路由器路由到 JMS 队列
Using Recipient List Router to route to JMS Queues
我可以使用收件人列表路由器从 HTTP 入站端点路由到 2 个 JMS 队列吗?我的目标是将消息从 HTTP 入站端点路由到 2 个 jms 队列,即订单和项目队列。我想使用收件人列表路由器来完成它。我不想使用发布子频道解决方案。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<import resource="queue-config.xml" />
<int:channel id="productChannel"/>
<int:channel id="jmsIn1">
<int:queue/>
</int:channel>
<int:channel id="jmsIn2">
<int:queue/>
</int:channel>
<!-- Want the orders from this endpoint to be placed in queues-->
<!-- Doesn't work even without <queue/> -->
<int-http:inbound-gateway supported-methods="PUT,POST"
path="/products/order" request-channel="productChannel">
</int-http:inbound-gateway>
<int:chain input-channel="productChannel">
<int:recipient-list-router id="jmsRouter">
<int:recipient channel="jmsIn1" />
<int:recipient channel="jmsIn2" />
</int:recipient-list-router>
<int:service-activator ref="orderHandler"
method="addOrder"/>
</int:chain>
<bean id="orderHandler" class="com.jms.OrderHandler" />
<int-jms:outbound-channel-adapter id="product.outbound.channel"
channel="jmsIn1" destination="orders.queue" />
<int-jms:outbound-channel-adapter id="records.outbound.channel"
channel="jmsIn2" destination="items.queue" />
</beans>
老实说,您的问题并不清楚。
<recipient-list-router>
确实。
您指定了多个 <recipient>
,它们中的每一个都会收到相同的消息。不管是 JMS 适配器还是其他任何东西都没有关系。
阅读你的问题,你甚至可以用 <publish-subscribe-channel>
做同样的事情:你需要用相同的 channel
引用指定几个 <int-jms:outbound-channel-adapter>
。
更新
您真的必须从日志和错误配置开始...
所以,让我们再看一次 StackTrace!
org.springframework.beans.factory.BeanCreationException: Error creating bean wit h name 'org.springframework.integration.handler.MessageHandlerChain#0': Invocati on of init method failed; nested exception is java.lang.IllegalArgumentException : All handlers except for the last one in the chain must implement the MessagePr oducer interface. Object of class [org.springframework.integration.router.RecipientListRouter] must be an instance of interface org.springframework.integration. core.MessageProducer
所以,它说你的 RecipientListRouter
必须是 MessageProducer
才能将消息转移到 <chain>
中的下一个处理程序,或者它必须是 [=] 中的最后一个组件18=]。
根据 Router
架构,它不是 AbstractReplyProducingMessageHandler
,例如 ServiceActivatingHandler
。
在路由器配置上有多项选择,我们只是没有正常的回复行为是合乎逻辑的。
因此,要启动您的任务,您只需将另一个处理程序移动到您的 <recipient-list-router>
映射!
我可以使用收件人列表路由器从 HTTP 入站端点路由到 2 个 JMS 队列吗?我的目标是将消息从 HTTP 入站端点路由到 2 个 jms 队列,即订单和项目队列。我想使用收件人列表路由器来完成它。我不想使用发布子频道解决方案。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<import resource="queue-config.xml" />
<int:channel id="productChannel"/>
<int:channel id="jmsIn1">
<int:queue/>
</int:channel>
<int:channel id="jmsIn2">
<int:queue/>
</int:channel>
<!-- Want the orders from this endpoint to be placed in queues-->
<!-- Doesn't work even without <queue/> -->
<int-http:inbound-gateway supported-methods="PUT,POST"
path="/products/order" request-channel="productChannel">
</int-http:inbound-gateway>
<int:chain input-channel="productChannel">
<int:recipient-list-router id="jmsRouter">
<int:recipient channel="jmsIn1" />
<int:recipient channel="jmsIn2" />
</int:recipient-list-router>
<int:service-activator ref="orderHandler"
method="addOrder"/>
</int:chain>
<bean id="orderHandler" class="com.jms.OrderHandler" />
<int-jms:outbound-channel-adapter id="product.outbound.channel"
channel="jmsIn1" destination="orders.queue" />
<int-jms:outbound-channel-adapter id="records.outbound.channel"
channel="jmsIn2" destination="items.queue" />
</beans>
老实说,您的问题并不清楚。
<recipient-list-router>
确实。
您指定了多个 <recipient>
,它们中的每一个都会收到相同的消息。不管是 JMS 适配器还是其他任何东西都没有关系。
阅读你的问题,你甚至可以用 <publish-subscribe-channel>
做同样的事情:你需要用相同的 channel
引用指定几个 <int-jms:outbound-channel-adapter>
。
更新
您真的必须从日志和错误配置开始...
所以,让我们再看一次 StackTrace!
org.springframework.beans.factory.BeanCreationException: Error creating bean wit h name 'org.springframework.integration.handler.MessageHandlerChain#0': Invocati on of init method failed; nested exception is java.lang.IllegalArgumentException : All handlers except for the last one in the chain must implement the MessagePr oducer interface. Object of class [org.springframework.integration.router.RecipientListRouter] must be an instance of interface org.springframework.integration. core.MessageProducer
所以,它说你的 RecipientListRouter
必须是 MessageProducer
才能将消息转移到 <chain>
中的下一个处理程序,或者它必须是 [=] 中的最后一个组件18=]。
根据 Router
架构,它不是 AbstractReplyProducingMessageHandler
,例如 ServiceActivatingHandler
。
在路由器配置上有多项选择,我们只是没有正常的回复行为是合乎逻辑的。
因此,要启动您的任务,您只需将另一个处理程序移动到您的 <recipient-list-router>
映射!