使用收件人列表路由器路由到JMS队列

时间:2015-10-16 16:19:21

标签: routing spring-integration

我可以使用收件人列表路由器从HTTP入站端点路由到2个JMS队列吗?我的目标是将消息从HTTP入站端点路由到2个jms队列,即订单和项目队列。我想使用收件人列表路由器来做到这一点。我不想使用pub子通道解决方案。

<?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>

1 个答案:

答案 0 :(得分:1)

说实话,你的问题并不清楚。

<recipient-list-router>完全确实

您指定了多个<recipient>,并且每个{}都将接收相同的消息。如果它是JMS适配器或其他任何东西都无关紧要。

阅读您的问题即使只使用<publish-subscribe-channel>,您也可以这样做:您需要使用相同的<int-jms:outbound-channel-adapter>引用指定多个channel

<强>更新

你真的必须从日志和错误配置开始......

所以,让我们再来看看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>中的下一个处理程序,或者它必须是<chain>中的最后一个组件}。

根据Router架构,它不是AbstractReplyProducingMessageHandler,例如ServiceActivatingHandler

在路由器配置上有多种选择,合乎逻辑的是我们没有正常的回复行为。

因此,为了完成您的任务,您应该再将一个处理程序移动到<recipient-list-router>映射!