camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: help with websphere MQ with XA transaction. Sample code below.
Date Sat, 03 Mar 2012 09:27:58 GMT
Hi

If you need XA then you need to use a XA transaction manager, as well
XA capable resources (in your case IBM WebSphereMQ) for the JMS broker
and then a XA JDBC driver for the JDBC.

So when you get the JDBC connection you need to get it in a way that
the XA transaction manager can orchestrate it.
I doubt by calling the code you do, works in that way. You may need to
check the documentation of your JDBC driver to learn how to do that.

Also if you got Camel in Action book, we cover all about transactions
and XA in chapter 9.
And have examples how to do XA with JMS and JDBC.


On Sat, Mar 3, 2012 at 1:31 AM, dmhatre <darpan27484@gmail.com> wrote:
> Hi Folks,
>   I am new to Apache camel. And got the JMS websphere MQ with camel.
> But I am struggling with XA transaction. Can somebody help me and give some
> leads to
> implement XA transaction. Below is the code sample which is working(but
> without XA transaction)
> The option transacted=true uses JMSTransactionManager which kind off
> rollbacks the JMS transaction
> if database transaction fails. But want some more control by doing commits
> and rollbacks manually.
> Thanks in advance.
>
>
> CamelContext context = new DefaultCamelContext();
>
> MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
>  cf.setHostName("192.111.111.11");
>  cf.setPort(1414);
>  cf.setQueueManager("QM_user");
>  cf.setChannel("S_user");
>  cf.setTransportType(1);
> JmsConfiguration jc = new JmsConfiguration(cf);
> JmsComponent ibmmq = new JmsComponent(jc);
>  context.addComponent("test-jms", ibmmq);
>
>  context.addRoutes(new RouteBuilder() {
>
>        public void configure() {
>
>        from("test-jms:queue:Q1?transacted=true").process(new Processor(){
>
>                public void process(Exchange arg0) throws Exception {
>
>                     Object obj = arg0.getIn().getBody();
>                     String sql = "insert into kk_testtab(x,y) values(?,?)";
>                     Connection conn = OceanviewDataSource.getConnection();
>                     PreparedStatement stmt = null;
>
>                        try {
>                                stmt = conn.prepareStatement(sql);
>
>                                stmt.setInt(1, Integer.parseInt(obj.toString()));
>                                stmt.setInt(2, Integer.parseInt(obj.toString()));
>
>                                stmt.execute();
>
>                                }catch(Exception e){
>                                        throw e;
>                                }finally {
>                                        conn.close();
>                                }
>                        });
>                }
>        });
>
>   context.start();
>   Thread.sleep(1000);
>   context.stop();
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/help-with-websphere-MQ-with-XA-transaction-Sample-code-below-tp5532697p5532697.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Mime
View raw message