You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ryan Stewart <rd...@gmail.com> on 2008/07/17 15:14:10 UTC
Local transaction spanning DB insert and JMS persistence
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?
--
View this message in context: http://www.nabble.com/Local-transaction-spanning-DB-insert-and-JMS-persistence-tp18507660s22882p18507660.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Local transaction spanning DB insert and JMS persistence
Posted by James Strachan <ja...@gmail.com>.
2008/7/18 Ryan Stewart <rd...@gmail.com>:
>
>
> 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
Re: Local transaction spanning DB insert and JMS persistence
Posted by Ryan Stewart <rd...@gmail.com>.
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.
--
View this message in context: http://www.nabble.com/Local-transaction-spanning-DB-insert-and-JMS-persistence-tp18507660s22882p18533071.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Local transaction spanning DB insert and JMS persistence
Posted by James Strachan <ja...@gmail.com>.
2008/7/17 Ryan Stewart <rd...@gmail.com>:
>
> 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