camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen J <stephen.joy...@mclaneco.com>
Subject Re: AW: JMS Transactions - How To
Date Thu, 31 Jan 2008 15:54:09 GMT

Thanks for all your help. This does indeed work. It seems the key is the
.policy(required) part of the chain. If this isn't in there then
transactions are not used.

I can use a modification of the code you've given me to do what I need. I
was wondering if there is a way to get the policy parts into my original
RouteBuilder class. Mostly just for aesthetic purposes as using the
RouteBuilder class is cleaner than writing the Spring plumbing code myself.
I'm not familiar enough with Camel and Spring to know if it's possible.

What I would like is for the result to look something like this:
public class MQRouter extends RouteBuilder {
	public static void main(String[] args) {
		new Main().run(args);
	}
	public void configure() {
        /*I don't know how to get camel to give me the transaction template
from the camel-context.xml */
		Policy required = new
SpringTransactionPolicy("myInjectedTransactionTemplate"));
		from("amq:integrator_test").policy(required).process(new Processor() {
			public void process(Exchange exch) throws Exception {
				System.out.println("Initiate print procedure. 
			}
		});
	}
}


Martin Krasser wrote:
> 
> Hi Stephen,
> 
> The java file was also removed by the spam filter. Here it is inline:
> .
> .
> .
>         // configure routes and add to camel context
>         camelContext.addRoutes(new SpringRouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 Policy required = new SpringTransactionPolicy(bean(
>                         TransactionTemplate.class,
> "PROPAGATION_REQUIRED"));
> 
>                 from("activemq:queue.a")
>                     // no error handler needed here
>                     .errorHandler(noErrorHandler()) 
>                     // installs transaction interceptor
>                     .policy(required)
>                     // throws exception causing a rollback
>                     .process(new Processor() {
>                     @Override
>                     public void process(Exchange exchange) throws
> Exception
> {
>                         // should be printed n times due to redeliveries
>                         System.out.println("exchange = " + exchange);
>                         // force rollback
>                         throw new Exception("test");
>                     }
>                 });
>             }
>         });
>     }
> .
> .
> .
> Cheers,
> Martin
> 
>> -----Urspr√ľngliche Nachricht-----
>> Von: Stephen J [mailto:stephen.joyner@mclaneco.com]
>> Gesendet: Mittwoch, 30. Januar 2008 21:54
>> An: camel-user@activemq.apache.org
>> Betreff: Re: AW: AW: JMS Transactions - How To
>> 
>> 
>> The configuration you suggested doesn't seem to work for me. I check it
>> using
>> both mqseries and activemq and in both cases the message was consumed
>> even
>> when an exception was thrown in the processing code.
>> 
>> Is there a specific way I need to configure my queues to handle
>> transactions?
>> 
>> Thanks for your help.
>> 
>> --
>> View this message in context: http://www.nabble.com/JMS-Transactions---
>> How-To-tp15168958s22882p15191800.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> 

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


Mime
View raw message