You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by James Strachan <ja...@gmail.com> on 2008/02/04 14:23:11 UTC

Re: AW: JMS Transactions - How To

On 31/01/2008, Stephen J <st...@mclaneco.com> wrote:
>
> Yes!! It works. Thanks to all who have helped me solve this issue!

Great stuff, thanks for letting us know.

This was quite a long and complex thread; are you now happy now? Or
were there still some gremlins in there trying to get transactions to
work nicely with your routes?

To get transactions to work nicely with any JMS it should just be a
matter of creating the Spring transaction manager and registering it
with the JMSComponent - is that your experience when using MQ?

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

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

Re: AW: JMS Transactions - How To

Posted by "tom.e.turner" <to...@macys.com>.
Hi,
Good thread and it helped, but I too, still have unsafe Transaction
Management in my Camel Consumer Route.  As mentioned the
TransactionInterceptor.process() method is called by the DeadLetterChannel
processing.  Thus, the message gets committed off the Queue before it can be
safely deposited elsewhere (or rolled back).  Any idea on how to have the
DeadLetterChannel.process() called by TransactionInterceptor.process()
instead of the other way around?  

Just put a breakpoint in the TransactionInterceptor.process(), look at the
stack trace and you'll see what I mean.

I'm still going to place the message on my Error Route, which is to the file
system, but if the Power goes at just the wrong time, I'll lose a message
for sure.

Thanks,
Tom
    public void process(final Exchange exchange) {
        LOG.info("transaction begin");

        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus
status) {
                try {
                    processNext(exchange);
                } catch (Exception e) {
                    throw new RuntimeCamelException(e);
                }
            }
        });

        LOG.info("transaction commit");
    }
-- 
View this message in context: http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p17200722.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: AW: JMS Transactions - How To

Posted by Stephen J <st...@mclaneco.com>.
Here's more information. It appears that the camel autowiring is not applying
the transaction policy to the router. 
When I manually set up everything with spring, executing the same code as in
my previous post I get the following(trimed) stack trace:
(executive summary: TransactionInterceptor catches the exception and doesn't
commit the transaction.)
----
INFO: Pre-instantiating singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@29b029b0:
defining beans
[camelContext,mqseries,jmsConfig,transactionPolicy,transactionTemplate,jmsTransactionManager,myProxyConnectionFactory,mqConFactory,messageProcessor,testProcessor,msgConfig];
root of factory hierarchy
Feb 11, 2008 10:59:32 AM org.apache.camel.spring.spi.TransactionInterceptor
process
INFO: transaction begin
Process code here....
Message body: testing
Feb 11, 2008 10:59:32 AM org.apache.camel.processor.Logger log
SEVERE: On delivery attempt: 0 caught:
org.apache.camel.RuntimeCamelException: java.lang.Exception: Test exception.
org.apache.camel.RuntimeCamelException: java.lang.Exception: Test exception.
	at
org.apache.camel.spring.spi.TransactionInterceptor$1.doInTransactionWithoutResult(TransactionInterceptor.java:49)
	at
org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
	at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
	at
org.apache.camel.spring.spi.TransactionInterceptor.process(TransactionInterceptor.java:44)
	at
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsynProcessorBridge.process(AsyncProcessorTypeConverter.java:44)
	at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:136)
	at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:86)
	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:56)
	at
org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:510)
	at
org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:445)
	at
org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:414)
	at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:309)
	at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:234)
	at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:871)
	at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:818)
	at java.lang.Thread.run(Thread.java:803)
Caused by: java.lang.Exception: Test exception.
	at mqprinter.TestProc.process(TestProc.java:14)
	at
org.apache.camel.processor.DelegateProcessor.processNext(DelegateProcessor.java:47)
	at
org.apache.camel.spring.spi.TransactionInterceptor.access$000(TransactionInterceptor.java:33)
	at
org.apache.camel.spring.spi.TransactionInterceptor$1.doInTransactionWithoutResult(TransactionInterceptor.java:47)
	... 18 more

-----
And here's the spring code setting up the transactionized message
processing:
	springContext = new
ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
	CamelContext camelContext =
SpringCamelContext.springCamelContext(springContext);
	camelContext.addRoutes(new SpringRouteBuilder() {	
	public void configure() throws Exception {
		Policy required = new
SpringTransactionPolicy((TransactionTemplate)springContext.getBean(
	                        "transactionTemplate")); 
		TestProc proc = (TestProc)springContext.getBean("testProcessor");
		from("mqseries:test").policy(required).process(proc);
	}
-----

It's probably just an incorrectly configured camelContext on my part, but
I'd be very appreciative if somebody could tell me how to get an xml route
to use the transaction policy I've specified.
Thanks to all.


Stephen J wrote:
> 
> Didn't help.
> Looking at the System.out from the Camel app when it tries to process the
> message I'd say the problem is that the transaction gets committed before
> the error processing happens. Here's a sample of the System.out where you
> see the commit message then the errors start dumping.
> 
> INFO: Pre-instantiating singletons in
> org.springframework.beans.factory.support.DefaultListableBeanFactory@33023302:
> defining beans
> [camelContext:beanPostProcessor,camelContext,mqseries,jmsConfig,transactionPolicy,transactionTemplate,jmsTransactionManager,myProxyConnectionFactory,mqConFactory,messageProcessor,testProcessor,msgConfig];
> root of factory hierarchy
> Feb 11, 2008 9:36:12 AM org.apache.camel.spring.spi.TransactionInterceptor
> process
> INFO: transaction begin
> Process code here....
> Message body: test
> Feb 11, 2008 9:36:12 AM org.apache.camel.spring.spi.TransactionInterceptor
> process
> INFO: transaction commit
> Feb 11, 2008 9:36:13 AM org.apache.camel.processor.Logger log
> SEVERE: On delivery attempt: 0 caught: java.lang.Exception: Test
> exception.
> java.lang.Exception: Test exception. at
> mqprinter.TestProc.process(TestProc.java:14) at
> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsynProcessorBridge.process(AsyncProcessorTypeConverter.java:44)
> 	at
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:136)
> 	at
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:86)
> 	at org.apache.camel.processor.Pipeline.process(Pipeline.java:103)
> 	at org.apache.camel.processor.Pipeline.process(Pipeline.java:87)
> 	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)
> ------
> Here's how I have my camelContext configured
> <camelContext xmlns="http://activemq.apache.org/camel/schema/spring" >
>    <route>
>    	<from uri="mqseries:test" />
>    	<policy ref="transactionPolicy" />
>    	<process ref="testProcessor" />
>    </route>
>   </camelContext> 
> ------
> Here's the testProcess code:
> public void process(Exchange exch) throws Exception {
>   System.out.println("Process code here....");
>   System.out.println("Message body: " + exch.getIn().getBody());
>   throw new Exception("Test exception.");
> }
> ------
> 
> 

-- 
View this message in context: http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p15415954.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: AW: JMS Transactions - How To

Posted by Stephen J <st...@mclaneco.com>.
Didn't help.
Looking at the System.out from the Camel app when it tries to process the
message I'd say the problem is that the transaction gets committed before
the error processing happens. Here's a sample of the System.out where you
see the commit message then the errors start dumping.

INFO: Pre-instantiating singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@33023302:
defining beans
[camelContext:beanPostProcessor,camelContext,mqseries,jmsConfig,transactionPolicy,transactionTemplate,jmsTransactionManager,myProxyConnectionFactory,mqConFactory,messageProcessor,testProcessor,msgConfig];
root of factory hierarchy
Feb 11, 2008 9:36:12 AM org.apache.camel.spring.spi.TransactionInterceptor
process
INFO: transaction begin
Process code here....
Message body: test
Feb 11, 2008 9:36:12 AM org.apache.camel.spring.spi.TransactionInterceptor
process
INFO: transaction commit
Feb 11, 2008 9:36:13 AM org.apache.camel.processor.Logger log
SEVERE: On delivery attempt: 0 caught: java.lang.Exception: Test exception.
java.lang.Exception: Test exception. at
mqprinter.TestProc.process(TestProc.java:14) at
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsynProcessorBridge.process(AsyncProcessorTypeConverter.java:44)
	at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:136)
	at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:86)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:103)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:87)
	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:56)
	at
org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:510)
	at
org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:445)
	at
org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:414)
	at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:309)
	at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:234)
	at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:871)
	at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:818)
	at java.lang.Thread.run(Thread.java:803)

------
Here's how I have my camelContext configured
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring" >
   <route>
   	<from uri="mqseries:test" />
   	<policy ref="transactionPolicy" />
   	<process ref="testProcessor" />
   </route>
  </camelContext> 
------
Here's the testProcess code:
public void process(Exchange exch) throws Exception {
  System.out.println("Process code here....");
  System.out.println("Message body: " + exch.getIn().getBody());
  throw new Exception("Test exception.");
}
------

James.Strachan wrote:
> 
> i wonder if setting CACHE_NONE for the cacheLevelName helps with MQ?
> 
> On 07/02/2008, Stephen J <st...@mclaneco.com> wrote:
>>
>> Actually after further investigation, the mqseries transactions don't
>> work if
>> I use the RouteBuilder method of starting the app. It works fine if I
>> start
>> the app with all the spring plumbing code, but not if I just Subclass
>> RouteBuilder. Very weird. Both techniques work with ActiveMQ so I'm not
>> sure
>> what the difference is between ActiveMQ and the mqseries systems.
>>
>>
>> James.Strachan wrote:
>> >
>> > On 31/01/2008, Stephen J <st...@mclaneco.com> wrote:
>> >>
>> >> Yes!! It works. Thanks to all who have helped me solve this issue!
>> >
>> > Great stuff, thanks for letting us know.
>> >
>> > This was quite a long and complex thread; are you now happy now? Or
>> > were there still some gremlins in there trying to get transactions to
>> > work nicely with your routes?
>> >
>> > To get transactions to work nicely with any JMS it should just be a
>> > matter of creating the Spring transaction manager and registering it
>> > with the JMSComponent - is that your experience when using MQ?
>> >
>> > --
>> > James
>> > -------
>> > http://macstrac.blogspot.com/
>> >
>> > Open Source Integration
>> > http://open.iona.com
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p15341624.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p15413139.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: AW: JMS Transactions - How To

Posted by ja...@gmail.com.
i wonder if setting CACHE_NONE for the cacheLevelName helps with MQ?

On 07/02/2008, Stephen J <st...@mclaneco.com> wrote:
>
> Actually after further investigation, the mqseries transactions don't work if
> I use the RouteBuilder method of starting the app. It works fine if I start
> the app with all the spring plumbing code, but not if I just Subclass
> RouteBuilder. Very weird. Both techniques work with ActiveMQ so I'm not sure
> what the difference is between ActiveMQ and the mqseries systems.
>
>
> James.Strachan wrote:
> >
> > On 31/01/2008, Stephen J <st...@mclaneco.com> wrote:
> >>
> >> Yes!! It works. Thanks to all who have helped me solve this issue!
> >
> > Great stuff, thanks for letting us know.
> >
> > This was quite a long and complex thread; are you now happy now? Or
> > were there still some gremlins in there trying to get transactions to
> > work nicely with your routes?
> >
> > To get transactions to work nicely with any JMS it should just be a
> > matter of creating the Spring transaction manager and registering it
> > with the JMSComponent - is that your experience when using MQ?
> >
> > --
> > James
> > -------
> > http://macstrac.blogspot.com/
> >
> > Open Source Integration
> > http://open.iona.com
> >
> >
>
> --
> View this message in context: http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p15341624.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>


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

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

Re: AW: JMS Transactions - How To

Posted by Stephen J <st...@mclaneco.com>.
Actually after further investigation, the mqseries transactions don't work if
I use the RouteBuilder method of starting the app. It works fine if I start
the app with all the spring plumbing code, but not if I just Subclass
RouteBuilder. Very weird. Both techniques work with ActiveMQ so I'm not sure
what the difference is between ActiveMQ and the mqseries systems.


James.Strachan wrote:
> 
> On 31/01/2008, Stephen J <st...@mclaneco.com> wrote:
>>
>> Yes!! It works. Thanks to all who have helped me solve this issue!
> 
> Great stuff, thanks for letting us know.
> 
> This was quite a long and complex thread; are you now happy now? Or
> were there still some gremlins in there trying to get transactions to
> work nicely with your routes?
> 
> To get transactions to work nicely with any JMS it should just be a
> matter of creating the Spring transaction manager and registering it
> with the JMSComponent - is that your experience when using MQ?
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/JMS-Transactions---How-To-tp15168958s22882p15341624.html
Sent from the Camel - Users mailing list archive at Nabble.com.