The transacted() will lookup in the Camel registry for a
TransactionMananger instance and hook into using that.
When using Spring XML files then that by declaring a spring <bean> tag
then its enlisted in the spring app context, which is where Camel will
look as well.

So if you do it manually from java code, you can enlist the
JmsTransactionManager yourself.

Just create a SimpleRegistry and add the TX manager to this registry.
And then pass that registry to the DefaultCamelContext ctr.


However if you only use JMS and you have already configured it to be
transactional, then you may omit using .transcated() in the Camel
route.
However if you use more resources such as JDBC etc. then you would
need to use the .transacted().

Also by using .transacted() you can see in the logs when a new TX is
begin / commit / rollback events.




On Thu, Aug 18, 2011 at 12:24 PM, szplayer <[email protected]> wrote:
> I'm trying to moving data from local folder(file) to ActiveMQ with calling a
> process, and ensuring no data lost during network failure or exception throw
> by the process. So TRANSACTION comes into my mind. But I can't get it run in
> Java DSL. (Spring DSL will be okay strangely.)
>
> public static void main(String[] args) throws Exception {
> ActiveMQConnectionFactory mqFactory = new
> ActiveMQConnectionFactory("tcp://localhost:61616");
>
>                PooledConnectionFactory mqConnPool = new 
> PooledConnectionFactory();
>                mqConnPool.setConnectionFactory(mqFactory);
>                mqConnPool.setMaxConnections(5);
>
>                JmsTransactionManager txnManager = new JmsTransactionManager();
>                txnManager.setConnectionFactory(mqConnPool);
>
>                ActiveMQComponent mqComponent = new ActiveMQComponent();
>                mqComponent.setConnectionFactory(mqConnPool);
>                mqComponent.setTransactionManager(txnManager);
>                mqComponent.setTransacted(true);
>                mqComponent.setUsePooledConnection(true);
>
>                CamelContext context;
>                context = new DefaultCamelContext();
>                context.addComponent("activemq",mqComponent);
>                context.addRoutes(new MyRouteBuilder());
>
>                context.start();
>
>                while (true)
>                {
>
>                }
> }
>
> private static class MyRouteBuilder extends RouteBuilder  {
>                @Override
>        public void configure() throws Exception {
>                        from("file:c:\\temp\\inbox")
>                                .transacted()
>                                .to("activemq:test")
>                                .process(new Processor() {
>                                        public void process(Exchange exchange) 
> throws Exception {
>                                                exchange.setException(new 
> Exception("abc"));
>                                        }
>                                });
>                }
>        }
>
> when run the problem, it throws
> Exception in thread "main" org.apache.camel.FailedToCreateRouteException:
> Failed to create route route1 at: >>> Policy[ref:null] <<<
>
> from previous post, i found that .transacted() is only work for Spring
> Transaction.
>
> is there any other solution to make it "transacted" ??
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Transaction-configuration-in-Java-DSL-tp4711625p4711625.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Reply via email to