You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by zigo <al...@gmail.com> on 2010/03/15 18:21:00 UTC

Request reply pattern with JMS and more replies to one request

Hi everybody,

I am trying to implement Request reply EIP using JMS and succeded quite
easily, thanks to Camel power :-D
Now I find myself in a strange situation: I need to implement this pattern
where I have one request message and possibly more than one reply,
correlated to the original request.
Is it possible with Camel and, in general, is it possible with JMS using
reply-to-queue and correlationId?

Plus: I found that even with a very simple configuration, the message
exchange is quite slow: average 1 second starting from a cxf endpoint and
without exiting from Camel. Here is my configuration:

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:cxf="http://camel.apache.org/schema/cxf"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
    	http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
    	http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd"
    >
    
    <import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	
	<import resource="classpath:activemq-config.xml" />

	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
		<route>
			<from
uri="cxf:bean:gtEndpoint?serviceName={http://www.my.com}gt_connector"/>
			<to uri="jms:gtIn?replyTo=gtOut" />
		</route>
		<route>
			<from uri="jms:gtIn" />
			<to uri="bean:gtMessageProcessor" />
			<to uri="jms:gtOut" />
		</route>
	</camelContext>
	
	<cxf:cxfEndpoint
		id="gtEndpoint" address="/gt"
		serviceClass="my.com.gt.GtConnector"
		wsdlURL="wsdl/gt_connector.wsdl"
	/>
	
	<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
		
	</bean>
	
	<bean id="gtMessageProcessor"
		  class="my.com.gt.GTMessageProcessor" />
</beans>

The bean is very simple, it just reads the request message and replies with
a constant string. The second route is just to mock the actual service.

This is my ActiveMQ configuration:

<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:amq="http://activemq.apache.org/schema/core"
	   xsi:schemaLocation="
		http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
		http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">

	<amq:broker useJmx="true" persistent="true" start="true">
		<amq:transportConnectors>
			<amq:transportConnector uri="tcp://localhost:61616" />
		</amq:transportConnectors>
	</amq:broker>

	<amq:queue id="gtIn" name="GT.IN" physicalName="GT.IN" />
	<amq:queue id="gtOut" name="GT.OUT" physicalName="GT.OUT" />

	<bean id="pooledJmsConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory"
		destroy-method="stop">
		<property name="connectionFactory">
			<amq:connectionFactory brokerURL="tcp://localhost:61616"
				id="jmsConnectionFactory" />
		</property>
	</bean>
 
	<bean id="jmsTransactionManager"
		class="org.springframework.jms.connection.JmsTransactionManager">
		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
	</bean>
 
</beans>

Thanks in advance

Alberto

-- 
View this message in context: http://old.nabble.com/Request-reply-pattern-with-JMS-and-more-replies-to-one-request-tp27907444p27907444.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Request reply pattern with JMS and more replies to one request

Posted by zigo <al...@gmail.com>.
Hi,

the bean gtMessageProcessor is just a mock object to test the whole loop. My
situation is the following:
- I am exposing a CXF Web Service with an InOut MEP.
- The CXF endpoint is part of a route that forwards the payload to a JMS
queue using request reply EIP.
- A third party system will read from the gtIn queue, process the data and
reply putting a message in the gtOut queue (with correlationId set).
- The CXF endpoint gets the message from the queue and put it in the
response message.

The whole interaction is synchronous, i.e. the web services client sends the
request and blocks, like a normal web services call, until the response
arrives or the call times out.

Now another requirement has been raised: I should be able to receive more
than one reply message, in the gtOut queue, correlated to the request
message. I should pass through  an aggregator (or a custom bean) which will
aggregate the reply messages and pass the result to the CXF endpoint. Any
hints on how to combine request-reply with aggregate? Or should I design the
route in a different way?

Regarding speed, I have checked the min, max and average times via JMX on
the single routes, and all the processing time appears to be in the first
route, the second route always takes 0 msec.

Alberto


willem.jiang wrote:
> 
> Hi,
> 
> Are you plan to send the multi replies in your gtMessageProcessor?
> If so , you can use ProducerTemplate[1] to do what you want.
> 
> For the message processing time, can you check if the gtMessageProcessor 
> take a long time to process the message?
> 
> [1]http://camel.apache.org/producertemplate.html
> 
> Willem
> 
> zigo wrote:
>> Hi everybody,
>> 
>> I am trying to implement Request reply EIP using JMS and succeded quite
>> easily, thanks to Camel power :-D
>> Now I find myself in a strange situation: I need to implement this
>> pattern
>> where I have one request message and possibly more than one reply,
>> correlated to the original request.
>> Is it possible with Camel and, in general, is it possible with JMS using
>> reply-to-queue and correlationId?
>> 
>> Plus: I found that even with a very simple configuration, the message
>> exchange is quite slow: average 1 second starting from a cxf endpoint and
>> without exiting from Camel. Here is my configuration:
>> 
>> <beans xmlns="http://www.springframework.org/schema/beans"
>>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>         xmlns:cxf="http://camel.apache.org/schema/cxf"
>>         xsi:schemaLocation="
>>         http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>     	http://camel.apache.org/schema/spring
>> http://camel.apache.org/schema/spring/camel-spring.xsd
>>     	http://camel.apache.org/schema/cxf
>> http://camel.apache.org/schema/cxf/camel-cxf.xsd"
>>     >
>>     
>>     <import resource="classpath:META-INF/cxf/cxf.xml" />
>> 	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
>> 	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>> 	
>> 	<import resource="classpath:activemq-config.xml" />
>> 
>> 	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>> 		<route>
>> 			<from
>> uri="cxf:bean:gtEndpoint?serviceName={http://www.my.com}gt_connector"/>
>> 			<to uri="jms:gtIn?replyTo=gtOut" />
>> 		</route>
>> 		<route>
>> 			<from uri="jms:gtIn" />
>> 			<to uri="bean:gtMessageProcessor" />
>> 			<to uri="jms:gtOut" />
>> 		</route>
>> 	</camelContext>
>> 	
>> 	<cxf:cxfEndpoint
>> 		id="gtEndpoint" address="/gt"
>> 		serviceClass="my.com.gt.GtConnector"
>> 		wsdlURL="wsdl/gt_connector.wsdl"
>> 	/>
>> 	
>> 	<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
>> 		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
>> 		
>> 	</bean>
>> 	
>> 	<bean id="gtMessageProcessor"
>> 		  class="my.com.gt.GTMessageProcessor" />
>> </beans>
>> 
>> The bean is very simple, it just reads the request message and replies
>> with
>> a constant string. The second route is just to mock the actual service.
>> 
>> This is my ActiveMQ configuration:
>> 
>> <beans xmlns="http://www.springframework.org/schema/beans"
>> 	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> 	   xmlns:amq="http://activemq.apache.org/schema/core"
>> 	   xsi:schemaLocation="
>> 		http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>> 		http://activemq.apache.org/schema/core
>> http://activemq.apache.org/schema/core/activemq-core.xsd">
>> 
>> 	<amq:broker useJmx="true" persistent="true" start="true">
>> 		<amq:transportConnectors>
>> 			<amq:transportConnector uri="tcp://localhost:61616" />
>> 		</amq:transportConnectors>
>> 	</amq:broker>
>> 
>> 	<amq:queue id="gtIn" name="GT.IN" physicalName="GT.IN" />
>> 	<amq:queue id="gtOut" name="GT.OUT" physicalName="GT.OUT" />
>> 
>> 	<bean id="pooledJmsConnectionFactory"
>> class="org.apache.activemq.pool.PooledConnectionFactory"
>> 		destroy-method="stop">
>> 		<property name="connectionFactory">
>> 			<amq:connectionFactory brokerURL="tcp://localhost:61616"
>> 				id="jmsConnectionFactory" />
>> 		</property>
>> 	</bean>
>>  
>> 	<bean id="jmsTransactionManager"
>> 		class="org.springframework.jms.connection.JmsTransactionManager">
>> 		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
>> 	</bean>
>>  
>> </beans>
>> 
>> Thanks in advance
>> 
>> Alberto
>> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Request-reply-pattern-with-JMS-and-more-replies-to-one-request-tp27907444p27916512.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Request reply pattern with JMS and more replies to one request

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

Are you plan to send the multi replies in your gtMessageProcessor?
If so , you can use ProducerTemplate[1] to do what you want.

For the message processing time, can you check if the gtMessageProcessor 
take a long time to process the message?

[1]http://camel.apache.org/producertemplate.html

Willem

zigo wrote:
> Hi everybody,
> 
> I am trying to implement Request reply EIP using JMS and succeded quite
> easily, thanks to Camel power :-D
> Now I find myself in a strange situation: I need to implement this pattern
> where I have one request message and possibly more than one reply,
> correlated to the original request.
> Is it possible with Camel and, in general, is it possible with JMS using
> reply-to-queue and correlationId?
> 
> Plus: I found that even with a very simple configuration, the message
> exchange is quite slow: average 1 second starting from a cxf endpoint and
> without exiting from Camel. Here is my configuration:
> 
> <beans xmlns="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xmlns:cxf="http://camel.apache.org/schema/cxf"
>         xsi:schemaLocation="
>         http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>     	http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
>     	http://camel.apache.org/schema/cxf
> http://camel.apache.org/schema/cxf/camel-cxf.xsd"
>     >
>     
>     <import resource="classpath:META-INF/cxf/cxf.xml" />
> 	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
> 	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
> 	
> 	<import resource="classpath:activemq-config.xml" />
> 
> 	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
> 		<route>
> 			<from
> uri="cxf:bean:gtEndpoint?serviceName={http://www.my.com}gt_connector"/>
> 			<to uri="jms:gtIn?replyTo=gtOut" />
> 		</route>
> 		<route>
> 			<from uri="jms:gtIn" />
> 			<to uri="bean:gtMessageProcessor" />
> 			<to uri="jms:gtOut" />
> 		</route>
> 	</camelContext>
> 	
> 	<cxf:cxfEndpoint
> 		id="gtEndpoint" address="/gt"
> 		serviceClass="my.com.gt.GtConnector"
> 		wsdlURL="wsdl/gt_connector.wsdl"
> 	/>
> 	
> 	<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
> 		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
> 		
> 	</bean>
> 	
> 	<bean id="gtMessageProcessor"
> 		  class="my.com.gt.GTMessageProcessor" />
> </beans>
> 
> The bean is very simple, it just reads the request message and replies with
> a constant string. The second route is just to mock the actual service.
> 
> This is my ActiveMQ configuration:
> 
> <beans xmlns="http://www.springframework.org/schema/beans"
> 	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	   xmlns:amq="http://activemq.apache.org/schema/core"
> 	   xsi:schemaLocation="
> 		http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
> 		http://activemq.apache.org/schema/core
> http://activemq.apache.org/schema/core/activemq-core.xsd">
> 
> 	<amq:broker useJmx="true" persistent="true" start="true">
> 		<amq:transportConnectors>
> 			<amq:transportConnector uri="tcp://localhost:61616" />
> 		</amq:transportConnectors>
> 	</amq:broker>
> 
> 	<amq:queue id="gtIn" name="GT.IN" physicalName="GT.IN" />
> 	<amq:queue id="gtOut" name="GT.OUT" physicalName="GT.OUT" />
> 
> 	<bean id="pooledJmsConnectionFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
> 		destroy-method="stop">
> 		<property name="connectionFactory">
> 			<amq:connectionFactory brokerURL="tcp://localhost:61616"
> 				id="jmsConnectionFactory" />
> 		</property>
> 	</bean>
>  
> 	<bean id="jmsTransactionManager"
> 		class="org.springframework.jms.connection.JmsTransactionManager">
> 		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
> 	</bean>
>  
> </beans>
> 
> Thanks in advance
> 
> Alberto
>