Local transaction spanning DB insert and JMS persistence

View: New views
4 Messages — Rating Filter:   Alert me  

Local transaction spanning DB insert and JMS persistence

by Ryan Stewart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a Camel route that runs in an ActiveMQ broker. This route stores some data in an Oracle database, and then puts a message on a persistent queue, which uses JDBC persistence and stores the data in that same database. I'd like both of these activities to occur in a single transaction. Since they both use the same database, this should be able to happen in a simple, local transaction. Is there any support for this in Camel or ActiveMQ?

Re: Local transaction spanning DB insert and JMS persistence

by James.Strachan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/7/17 Ryan Stewart <rds6235@...>:
>
> I have a Camel route that runs in an ActiveMQ broker. This route stores some
> data in an Oracle database, and then puts a message on a persistent queue,
> which uses JDBC persistence and stores the data in that same database. I'd
> like both of these activities to occur in a single transaction. Since they
> both use the same database, this should be able to happen in a simple, local
> transaction. Is there any support for this in Camel or ActiveMQ?

Sure - though when using JDBC and JMS together you need to use JTA and
XA. While ActiveMQ can support Oracle as a persistence option, on the
ActiveMQ broker - it cannot currently take part in a JDBC-only
persistence transaction on the JMS client side. Currently the broker
side use of JDBC persistence is a separate transaction.

To use JTA / XA just create a Spring JTA transaction manager and
register it with the JDBC and JMS components.
--
James
-------
http://macstrac.blogspot.com/

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

Re: Local transaction spanning DB insert and JMS persistence

by Ryan Stewart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James.Strachan wrote:
Sure - though when using JDBC and JMS together you need to use JTA and
XA. While ActiveMQ can support Oracle as a persistence option, on the
ActiveMQ broker - it cannot currently take part in a JDBC-only
persistence transaction on the JMS client side. Currently the broker
side use of JDBC persistence is a separate transaction.

To use JTA / XA just create a Spring JTA transaction manager and
register it with the JDBC and JMS components.
Yes, this is what I'm trying to figure a way through. I don't want to use XA. All of the database work is coming from the same box and going to the same database. I'd like to use the same DB connection to do some of my own work and then store the broker's persistence data so that it can be enclosed in a local transaction. I see that the transaction is managed internally, so I was thinking of handing ActiveMQ a proxied java.sql.Connection object that will intercept the commit call and make sure that all of the combined work is committed properly.

Re: Local transaction spanning DB insert and JMS persistence

by James.Strachan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/7/18 Ryan Stewart <rds6235@...>:

>
>
> James.Strachan wrote:
>>
>> Sure - though when using JDBC and JMS together you need to use JTA and
>> XA. While ActiveMQ can support Oracle as a persistence option, on the
>> ActiveMQ broker - it cannot currently take part in a JDBC-only
>> persistence transaction on the JMS client side. Currently the broker
>> side use of JDBC persistence is a separate transaction.
>>
>> To use JTA / XA just create a Spring JTA transaction manager and
>> register it with the JDBC and JMS components.
>>
>
> Yes, this is what I'm trying to figure a way through. I don't want to use
> XA. All of the database work is coming from the same box and going to the
> same database. I'd like to use the same DB connection to do some of my own
> work and then store the broker's persistence data so that it can be enclosed
> in a local transaction. I see that the transaction is managed internally, so
> I was thinking of handing ActiveMQ a proxied java.sql.Connection object that
> will intercept the commit call and make sure that all of the combined work
> is committed properly.

Thats currently not possible with ActiveMQ I'm afraid.

The easiest thing is to store messages as entity beans in some table;
then get the ActiveMQ broker to bridge from the table to some queue in
a separate process.

e.g.

<route>
  <from uri="jpa:com.acme.MyMessageEntity"/>
  <to uri="activemq:SomeQueue"/>
</route>

Then you can use hibernate or whatever in your application to send
messages without using XA.

BTW you can also use a CamelDestination with the ActiveMQ JMS API; so
your JMS code can send to, say, new
CamelQueueDestination("jpa:com.acme.MyMessageEntity"/> to achieve the
same thing but fooling your JMS code into thinking you're doing a pure
JMS call when really just using JPA

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

Open Source Integration
http://open.iona.com
LightInTheBox - Buy quality products at wholesale price
Need professional support or training for Apache Camel? Graphic Design by Hiram and the Nabble Forum configured by James