You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by agentalpha <yo...@gmail.com> on 2014/10/16 16:41:52 UTC

ActiveMQ InOut JMS messaging with external system

Hi Everyone,

I have a route where the final destination is:
activemq:queue:soapRequestQ?exchangePattern=InOut&asyncConsumer=true&useMessageIDAsCorrelationID=false&replyTo=responseQ&replyToType=Shared&requestTimeout=30000&transacted=false

In another route I have following configuration:
<route id="soapReqQToResQ">
		<from uri="activemq:queue:soapRequestQ"/>
		<process ref="headerProcessor"/>
		<process ref="openAPISimulator"/>
		
</route>

Using this configuration, the activemq inout messaging works perfectly fine
and I can achieve non blocking http request-response kind of behaviour using
this.

But when I try to do what second route is doing using a stand along activemq
java client, the inout message times out after configured time for not
getting any response. This is my java client part of code:
MessageConsumer consumer = session.createConsumer(request);// where request
is soapRequestQ
MessageProducer producer = session.createProducer(response);// where
response is responseQ

Message message = consumer.receive(1000);
if(message2 != null) {
				ActiveMQMapMessage activeMQMapMessage = (ActiveMQMapMessage) message;
				Map content = activeMQMapMessage.getContentMap();
				System.out.println("Received Message soapRequestQ: " + content);
				Map response = new HashMap();
				response.put("returnCode", "0");
				response.put("errorKey", "SUCCESS");
								
				try {
				// Convert Map to byte array
			    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
			    ObjectOutputStream out = new ObjectOutputStream(byteOut);
				out.writeObject(response);
				ByteSequence byteSequence = new ByteSequence(byteOut.toByteArray());
				ActiveMQMapMessage responseMapMessage = new ActiveMQMapMessage();
				responseMapMessage.setContent(byteSequence);
				responseMapMessage.setJMSDestination(response);
			
responseMapMessage.setJMSCorrelationID(activeMQMapMessage.getJMSCorrelationID());
			
responseMapMessage.setCorrelationId(activeMQMapMessage.getCorrelationId());
				
				producer.send(responseMapMessage);
				
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

I can see the message in responseQ. But it is not pickedup by camel for
InOut response.
Am I missing anything?
How the request-response in InOut pattern is connected? How does Camel auto
connects request and response in jms? I thought that JMSCorelationId was
enough for that. But it doesn't seems to be that way.
Please advice.
Thanks.

BR!
Yogesh



--
View this message in context: http://camel.465427.n5.nabble.com/ActiveMQ-InOut-JMS-messaging-with-external-system-tp5757630.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ActiveMQ InOut JMS messaging with external system

Posted by Christian Mueller <ch...@gmail.com>.
Have a look at [1].

[1]
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java;h=84b20a28fc73da7ff55ff4ad61dde64f2ed8ceb3;hb=HEAD

Best,
Christian



--
View this message in context: http://camel.465427.n5.nabble.com/ActiveMQ-InOut-JMS-messaging-with-external-system-tp5757630p5758112.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ActiveMQ InOut JMS messaging with external system

Posted by agentalpha <yo...@gmail.com>.
Update:

Just for testing, I tried sending the same message back in the response and
it worked fine. But If I'm creating a new ActiveMQMapMessage and set
following:

ActiveMQMapMessage responseMapMessage = new ActiveMQMapMessage(); //(I also
tried copying original message and setting below properties)
responseMapMessage.setContent(byteSequence);
responseMapMessage.storeContent();
responseMapMessage.setJMSDestination(destination4);
responseMapMessage.setJMSCorrelationID(activeMQMapMessage.getJMSCorrelationID());
responseMapMessage.setReplyTo(null);
responseMapMessage.setJMSReplyTo(null);
responseMapMessage.setMessageId(activeMQMapMessage.getMessageId());
responseMapMessage.setCorrelationId(activeMQMapMessage.getCorrelationId());

producer.send(responseMapMessage);

where producer is for queue: responseQ as mention above in the description,
then it doesn't work and the route times out for no response.

For investigation, I also tried adding a consumer for this queue and see If
I'm getting message on this queue and it was successful. The consumer was
able to consumer the message.

But then why camel activemq was not able to read and correlate that message
response with its original request in this case? And why it was able to
correlate when I sent the same activemqmapmessage (the one  sent by camel
itself as request) in the response by producer?
Is there any property which I'm missing to set in the response message?
Please let me know.
Thanks.

Yogesh



--
View this message in context: http://camel.465427.n5.nabble.com/ActiveMQ-InOut-JMS-messaging-with-external-system-tp5757630p5758084.html
Sent from the Camel - Users mailing list archive at Nabble.com.