Reputation: 732
Can I use a recipient list router to route to 2 JMS Queues from an HTTP Inbound Endpoint? My goal is to route messages from the HTTP Inbound Endpoint to 2 jms queues i.e. orders and items queue. I want to use the recipient list router to do it. I don't want to use the pub sub channel solution.
<?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>
Upvotes: 1
Views: 869
Reputation: 121442
To be honest your issue isn't clear.
The <recipient-list-router>
exactly does that.
You specify several <recipient>
and each of them will receiver the same message. And it doesn't matter if it will be JMS Adapters or anything else.
Reading your question you can do the same even just with <publish-subscribe-channel>
: you need to specify several <int-jms:outbound-channel-adapter>
with the same channel
reference.
UPDATE
You really had to start from the logs and your misconfiguration...
So, let's take a look to the StackTrace one more time!
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
So, it says that your RecipientListRouter
must be MessageProducer
to shift a message to the next handler in the <chain>
or it must be as the last component in the <chain>
.
According to the Router
architecture it isn't AbstractReplyProducingMessageHandler
, like ServiceActivatingHandler
, for example.
Having multi choice on the router config, it is logical that we just don't have there the normal reply behavior.
So, to kick your task you just should move one more handler to your <recipient-list-router>
mapping!
Upvotes: 1