You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Lars Ivar Igesund <la...@igesund.net> on 2008/09/30 13:26:57 UTC

Getting a reply to an exchange over JMS

Hi!

I need to do a synchronous request over JMS, and I was told this can be done 
by using an InOut exchange. So I am doing something like this:

public Object sendSync(Object message, Address recipient, Map<String, Object> 
hdrs) {
	
	CamelTemplate<Exchange> template = new CamelTemplate<Exchange>( 
routeContext );
	Map<String, Object> headers = new HashMap<String, Object>();
	if (hdrs != null)
		headers.putAll(hdrs);
	headers.put( "to", recipient.getAsString() );
	headers.put( "from", address.getAsString() );
		
	DefaultExchange exchange = new DefaultExchange(routeContext);
	exchange.setPattern(ExchangePattern.InOut);
	exchange.getIn().setBody(message);
	exchange.getIn().setHeaders(headers);
	
	return template.send("seda:outbox", exchange);
}

and in the other end:

from("myqueu").process(new MyProcessor());

and MyProcessor does

	Message m = exchange.getOut(true);
	m.setBody(retpm);
	exchange.setOut(m);

The exhange is processed, but the sendSync does not seem to return, and after 
a short while I start getting 

org.apache.camel.ExchangeTimedOutException: The OUT message was not received 
within: 20000 millis on the exchange: Exchange[JmsMessage: 
PersonMessage[action=AUTHENTICATE,person=<null>]]
org.apache.camel.ExchangeTimedOutException: The OUT message was not received 
within: 20000 millis on the exchange: Exchange[JmsMessage: 
PersonMessage[action=AUTHENTICATE,person=<null>]]
	at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:114)
	at 
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsynProcessorBridge.process(AsyncProcessorTypeConverter.java:44)
	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:73)
	at 
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:143)
	at 
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:87)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:85)
	at 
org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:40)
	at 
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:44)
	at 
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:68)
	at 
org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:66)
	at 
org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:531)
	at 
org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:466)
	at 
org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:435)
	at 
org.springframework.jms.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:407)
	at 
org.springframework.jms.listener.SimpleMessageListenerContainer$2.onMessage(SimpleMessageListenerContainer.java:204)
	at 
org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:967)
	at 
org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:122)
	at 
org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:192)
	at 
org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
	at 
org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
	at 
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
	at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
	at java.lang.Thread.run(Thread.java:619)


I suppose I am missing something to finish off the exchange, but I can't seem 
to find any references to what this is. To me it seems I'm doing what is 
hinted to in some earlier mailing list discussions.

We are currently using Camel 1.3.0

Best regards,
Lars Ivar Igesund
	

Re: Getting a reply to an exchange over JMS

Posted by Lars Ivar Igesund <la...@igesund.net>.
On Tuesday 30 September 2008 13:36:46 James Strachan wrote:
> 2008/9/30 Lars Ivar Igesund <la...@igesund.net>:
> > Hi!
> >
> > I need to do a synchronous request over JMS, and I was told this can be
> > done by using an InOut exchange.
>
> It sure can - e.g. try doing some remoting over JMS...
> http://activemq.apache.org/camel/spring-remoting.html

Indeed - after some sparring on IRC with you guys, I got it working. My 
issue(s) were that there was an .to() after the process + me expecting the 
body where I got the exchange.

Thanks!

Best regards,
Lars Ivar Igesund



Re: Getting a reply to an exchange over JMS

Posted by James Strachan <ja...@gmail.com>.
2008/9/30 Lars Ivar Igesund <la...@igesund.net>:
> Hi!
>
> I need to do a synchronous request over JMS, and I was told this can be done
> by using an InOut exchange.

It sure can - e.g. try doing some remoting over JMS...
http://activemq.apache.org/camel/spring-remoting.html


> So I am doing something like this:
>
> public Object sendSync(Object message, Address recipient, Map<String, Object>
> hdrs) {
>
>        CamelTemplate<Exchange> template = new CamelTemplate<Exchange>(
> routeContext );
>        Map<String, Object> headers = new HashMap<String, Object>();
>        if (hdrs != null)
>                headers.putAll(hdrs);
>        headers.put( "to", recipient.getAsString() );
>        headers.put( "from", address.getAsString() );
>
>        DefaultExchange exchange = new DefaultExchange(routeContext);
>        exchange.setPattern(ExchangePattern.InOut);
>        exchange.getIn().setBody(message);
>        exchange.getIn().setHeaders(headers);
>
>        return template.send("seda:outbox", exchange);
> }

BTW you can use the template.request*() methods instead of sending
with a custom pattern.


> and in the other end:
>
> from("myqueu").process(new MyProcessor());
>
> and MyProcessor does
>
>        Message m = exchange.getOut(true);
>        m.setBody(retpm);
>        exchange.setOut(m);
>
> The exhange is processed, but the sendSync does not seem to return, and after
> a short while I start getting
>
> org.apache.camel.ExchangeTimedOutException: The OUT message was not received
> within: 20000 millis on the exchange: Exchange[JmsMessage:
> PersonMessage[action=AUTHENTICATE,person=<null>]]
> org.apache.camel.ExchangeTimedOutException: The OUT message was not received
> within: 20000 millis on the exchange: Exchange[JmsMessage:
> PersonMessage[action=AUTHENTICATE,person=<null>]]
>        at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:114)
>        at
> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsynProcessorBridge.process(AsyncProcessorTypeConverter.java:44)
>        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:73)
>        at
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:143)
>        at
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:87)
>        at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
>        at org.apache.camel.processor.Pipeline.process(Pipeline.java:85)
>        at
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:40)
>        at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:44)
>        at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:68)
>        at
> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:66)
>        at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:531)
>        at
> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:466)
>        at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:435)
>        at
> org.springframework.jms.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:407)
>        at
> org.springframework.jms.listener.SimpleMessageListenerContainer$2.onMessage(SimpleMessageListenerContainer.java:204)
>        at
> org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:967)
>        at
> org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:122)
>        at
> org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:192)
>        at
> org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
>        at
> org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>        at java.lang.Thread.run(Thread.java:619)
>
>
> I suppose I am missing something to finish off the exchange, but I can't seem
> to find any references to what this is. To me it seems I'm doing what is
> hinted to in some earlier mailing list discussions.
>
> We are currently using Camel 1.3.0

Could you try 1.4.0 - I can't remember when JMS InOut support was added?

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com