2015-10-16 33 views
1

我可以使用收件人列表路由器從HTTP入站端點路由到2個JMS隊列嗎?我的目標是將來自HTTP入站端點的消息路由到2個jms隊列,即訂單和項目隊列。我想使用收件人列表路由器來執行此操作。我不想使用pub pub子頻道解決方案。使用收件人列表路由器路由到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> 
+0

我嘗試使用收件人列表使用jms出站適配器,但我得到以下exceptionorg.springframework.beans.factory.BeanCreationException:創建bean智慧錯誤 h name'org.springframework.integration.handler.MessageHandlerChain#0':初始化方法的Invocati 失敗;嵌套的例外是java.lang.IllegalArgumentException異常 :除了最後一個鏈必須實現MessagePr oducer接口的所有處理器。類[org.springframework.integration.router.Recipi entListRouter]的對象必須是接口org.springframework.integration的實例。 core.MessageProducer – BreenDeen

+0

的目標是:處理I增加了更多的清晰度和一些代碼的消息 – BreenDeen

回答

1

說實話,你的問題並不清楚。

<recipient-list-router>恰好確實那。

您指定了幾個<recipient>並且它們中的每一個都將接收相同的消息。如果它將成爲JMS適配器或其他任何東西都沒關係。

閱讀你的問題,你甚至可以用<publish-subscribe-channel>做同樣的事情:你需要指定幾個<int-jms:outbound-channel-adapter>channel相同的參考。

UPDATE

你真的不得不從日誌和錯誤配置的開始......

那麼,讓我們來看看在堆棧跟蹤一個更多的時間!

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>映射!

+0

之前,保存進入HTTP端點消息直接進入2個JMS隊列。對不起,如果不明確。我不想使用。 – BreenDeen

+0

查看我答案中的更新。請下次再提供更多信息。 –

+0

我弄清楚了堆棧跟蹤問題的原因。然而,我的理解是,我將不得不提供一個將MessageProducerSupport擴展到收件人列表路由器的類,我認爲這會太多工作。我使用帶有自動裝配的jmstemplate的服務激活器並使用工作,但我的首選是使用收件人列表路由器。所以從你的答案我的理解是,這是不能做到的。謝謝 – BreenDeen