Hi Stephen,
The java file was also removed by the spam filter. Here it is inline:
import org.apache.camel.CamelContext;
import org.apache.camel.CamelTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.spi.Policy;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.spring.SpringRouteBuilder;
import org.apache.camel.spring.spi.SpringTransactionPolicy;
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.Lifecycle;
import org.springframework.transaction.support.TransactionTemplate;
public class RollbackExample {
private static ApplicationContext springContext;
private static CamelContext camelContext;
private static CamelTemplate camelTemplate;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// setup application context and camel context
springContext = new ClassPathXmlApplicationContext("/context.xml");
camelContext = getCamelContext(springContext);
// create camel template for sending messages
camelTemplate = getCamelTemplate(camelContext);
// 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");
}
});
}
});
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
((Lifecycle)springContext).stop();
}
@Test
public void testRollback() throws InterruptedException {
camelTemplate.sendBody("activemq:queue.a", "blah");
// wait for 20 seconds to see redeliveries
// (exchange string rep. written to stdout)
Thread.sleep(20000L);
}
private static SpringCamelContext getCamelContext(ApplicationContext
springContext) {
return (SpringCamelContext)springContext.getBean("camel");
}
private static CamelTemplate getCamelTemplate(CamelContext camelContext)
{
return new CamelTemplate(camelContext);
}
}
Cheers,
Martin
> -----Ursprüngliche Nachricht-----
> Von: Stephen J [mailto:[EMAIL PROTECTED]
> Gesendet: Mittwoch, 30. Januar 2008 21:54
> An: [email protected]
> 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.