You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by anish pathadan <an...@gmail.com> on 2007/09/20 13:07:03 UTC

Help! Unable to send messages to activemq from an XA transaction

Hi All,
       I am trying to send messages to active mq within an XA transaction. I
used jdbc persistence and VM connector. When tried to send message I am
getting an error "unable to set autocommit on within an XA
transaction". This is what I find out after the analysis.

org.apache.activemq.store.jdbc.TransactionContext's getConnection() and
close() methods tries to set autocommit ON on the jdbc connection. This will
cause the above said exception because getConnection() and close() method is
called within an XA transaction. There is check in this method to see
whether the method is called within a transaction or not. But the variable
is having incorrect value when called within an XA transaction.

My question is how can I determine whether the method is called within an XA
transaction or not?. Or is there any otherway to solve this issue?
Best Regards,
Anish Pathadan

Re: Help! Unable to send messages to activemq from an XA transaction

Posted by anish pathadan <an...@gmail.com>.
Hi All,
     Finally with the help of James and Davies I figured out the problem ,
we shouldn't use an external XA datasource for Broker persistence.I got it
working when I used a non XA datasource.

On 9/25/07, anish pathadan <an...@gmail.com> wrote:
>
> Hi,
> The first time the problem comes when ConsumerInfo message is send while
> creating a connection. I have attached a stack trace upto calling the
> getConnection(). The getConnection() method code is as follows
>
> connection
> = dataSource.getConnection();
>
> *boolean* autoCommit = !inTx;
>
> *if* (connection.getAutoCommit() != autoCommit) {
>
> connection.setAutoCommit(autoCommit);
>
> }
>
> In this *inTx* is false, which will result in setting autoCommit to true
> for an XA connection. begin() method is the only place in which *inTx* is
> set to true. In this case the JDBCPersistenceAdapter just creates a new
> TransactionContext and without calling the begin it uses that for issuing
> getConnection(). Can I pass the Xid information that is available earlier in
> the stack trace to check whether the connection is XA or not. Or is there
> any other better way to do it.
>
> TransactionContext.getConnection() line: 58
> DefaultJDBCAdapter.doGetDestinations(TransactionContext) line: 566
> JDBCPersistenceAdapter.getDestinations() line: 95
> JournalPersistenceAdapter.getDestinations () line: 145
> DestinationFactoryImpl.getDestinations() line: 70
> ManagedTopicRegion(AbstractRegion).getInactiveDestinations() line: 256
> ManagedTopicRegion(TopicRegion).getInactiveDestinations() line: 256
> ManagedTopicRegion(AbstractRegion).addConsumer(ConnectionContext,
> ConsumerInfo) line: 212
> ManagedTopicRegion(TopicRegion).addConsumer(ConnectionContext,
> ConsumerInfo) line: 110
> ManagedRegionBroker(RegionBroker).addConsumer(ConnectionContext,
> ConsumerInfo) line: 340
> TransactionBroker(BrokerFilter).addConsumer(ConnectionContext,
> ConsumerInfo) line: 86
> AdvisoryBroker.addConsumer(ConnectionContext, ConsumerInfo) line: 78
> CompositeDestinationBroker(BrokerFilter).addConsumer(ConnectionContext,
> ConsumerInfo) line: 86
> BrokerService$2(MutableBrokerFilter).addConsumer(ConnectionContext,
> ConsumerInfo) line: 96
> TransportConnection.processAddConsumer(ConsumerInfo) line: 586
> ConsumerInfo.visit(CommandVisitor) line: 313
> TransportConnection.service(Command) line: 294
> TransportConnection$1.onCommand(Object) line: 185
> ResponseCorrelator.onCommand(Object) line: 95
> MutexTransport(TransportFilter).onCommand(Object) line: 65
> VMTransportServer$1(VMTransport).syncOneWay(Object) line: 96
> VMTransportServer$1(VMTransport).oneway(Object) line: 83
> MutexTransport.oneway(Object) line: 47
> ResponseCorrelator.asyncRequest(Object, ResponseCallback) line: 69
> ResponseCorrelator.request(Object) line: 74
> ActiveMQConnection.syncSendPacket(Command) line: 1175
> AdvisoryConsumer.<init>(ActiveMQConnection, ConsumerId) line: 46
> ActiveMQConnection.ensureConnectionInfoSent() line: 1272
> TransactionContext.setXid(Xid) line: 554
> TransactionContext.start(Xid, int) line: 299
> ActiveMQManagedConnection$1(LocalAndXATransaction).start(Xid, int) line:
> 136
>
>
>
> On 9/25/07, anish pathadan <an...@gmail.com> wrote:
>
> > Hi
> >    The problem happens only if I use an external XA datasource.I used XA
> > datasource created in geronimo.This datasource is set inthe Persistence
> > adapter factory before starting the brokerservice.
> > It seems that Activemq doesn't recognise it as an XA datasource and
> > tries to set autocommit to true in TransactionContext. I think the problem
> > can be solved if I can somehow know whether the transaction is XA or not in
> > org.apache.activemq.store.jdbc.TransactionContext.
> > The question is how can I know that???. Or is there any other better way
> > to solve it?
> >
> >
> > On 9/20/07, anish pathadan <anishpathadan@gmail.com > wrote:
> >
> > > Hi Hiram,
> > > Thanks for that info.I used the default derby database.I will try
> > > creating an XA datasouce and using it.
> > >
> > > On 9/20/07, Hiram Chirino <hiram@hiramchirino.com > wrote:
> > > >
> > > > How did you configure the ActiveMQ datasource?  It's data source
> > > > should be setup as an XA datasource.
> > > >
> > > > On 9/20/07, anish pathadan <an...@gmail.com> wrote:
> > > > > Hi All,
> > > > >        I am trying to send messages to active mq within an XA
> > > > transaction. I
> > > > > used jdbc persistence and VM connector. When tried to send message
> > > > I am
> > > > > getting an error "unable to set autocommit on within an XA
> > > > > transaction". This is what I find out after the analysis.
> > > > >
> > > > > org.apache.activemq.store.jdbc.TransactionContext's
> > > > getConnection() and
> > > > > close() methods tries to set autocommit ON on the jdbc connection.
> > > > This will
> > > > > cause the above said exception because getConnection() and close()
> > > > method is
> > > > > called within an XA transaction. There is check in this method to
> > > > see
> > > > > whether the method is called within a transaction or not. But the
> > > > variable
> > > > > is having incorrect value when called within an XA transaction.
> > > > >
> > > > > My question is how can I determine whether the method is called
> > > > within an XA
> > > > > transaction or not?. Or is there any otherway to solve this issue?
> > > > > Best Regards,
> > > > > Anish Pathadan
> > > > >
> > > >
> > > >
> > > > --
> > > > Regards,
> > > > Hiram
> > > >
> > > > Blog: http://hiramchirino.com
> > > >
> > >
> > >
> > >
> > > --
> > > Best Regards,
> > > Anish Pathadan
> >
> >
> >
> >
> > --
> > Best Regards,
> > Anish Pathadan
>
>
>
>
> --
> Best Regards,
> Anish Pathadan




-- 
Best Regards,
Anish Pathadan

Re: Help! Unable to send messages to activemq from an XA transaction

Posted by anish pathadan <an...@gmail.com>.
Hi,
The first time the problem comes when ConsumerInfo message is send while
creating a connection. I have attached a stack trace upto calling the
getConnection(). The getConnection() method code is as follows

connection = dataSource.getConnection();

*boolean* autoCommit = !inTx;

*if* (connection.getAutoCommit() != autoCommit) {

connection.setAutoCommit(autoCommit);

}

In this *inTx* is false, which will result in setting autoCommit to true for
an XA connection. begin() method is the only place in which *inTx* is set to
true. In this case the JDBCPersistenceAdapter just creates a new
TransactionContext and without calling the begin it uses that for issuing
getConnection(). Can I pass the Xid information that is available earlier in
the stack trace to check whether the connection is XA or not. Or is there
any other better way to do it.

TransactionContext.getConnection() line: 58
DefaultJDBCAdapter.doGetDestinations(TransactionContext) line: 566
JDBCPersistenceAdapter.getDestinations() line: 95
JournalPersistenceAdapter.getDestinations() line: 145
DestinationFactoryImpl.getDestinations() line: 70
ManagedTopicRegion(AbstractRegion).getInactiveDestinations() line: 256
ManagedTopicRegion(TopicRegion).getInactiveDestinations() line: 256
ManagedTopicRegion(AbstractRegion).addConsumer(ConnectionContext,
ConsumerInfo) line: 212
ManagedTopicRegion(TopicRegion).addConsumer(ConnectionContext, ConsumerInfo)
line: 110
ManagedRegionBroker(RegionBroker).addConsumer(ConnectionContext,
ConsumerInfo) line: 340
TransactionBroker(BrokerFilter).addConsumer(ConnectionContext, ConsumerInfo)
line: 86
AdvisoryBroker.addConsumer(ConnectionContext, ConsumerInfo) line: 78
CompositeDestinationBroker(BrokerFilter).addConsumer(ConnectionContext,
ConsumerInfo) line: 86
BrokerService$2(MutableBrokerFilter).addConsumer(ConnectionContext,
ConsumerInfo) line: 96
TransportConnection.processAddConsumer(ConsumerInfo) line: 586
ConsumerInfo.visit(CommandVisitor) line: 313
TransportConnection.service(Command) line: 294
TransportConnection$1.onCommand(Object) line: 185
ResponseCorrelator.onCommand(Object) line: 95
MutexTransport(TransportFilter).onCommand(Object) line: 65
VMTransportServer$1(VMTransport).syncOneWay(Object) line: 96
VMTransportServer$1(VMTransport).oneway(Object) line: 83
MutexTransport.oneway(Object) line: 47
ResponseCorrelator.asyncRequest(Object, ResponseCallback) line: 69
ResponseCorrelator.request(Object) line: 74
ActiveMQConnection.syncSendPacket(Command) line: 1175
AdvisoryConsumer.<init>(ActiveMQConnection, ConsumerId) line: 46
ActiveMQConnection.ensureConnectionInfoSent() line: 1272
TransactionContext.setXid(Xid) line: 554
TransactionContext.start(Xid, int) line: 299
ActiveMQManagedConnection$1(LocalAndXATransaction).start(Xid, int) line:
136


On 9/25/07, anish pathadan <an...@gmail.com> wrote:

> Hi
>    The problem happens only if I use an external XA datasource.I used XA
> datasource created in geronimo.This datasource is set inthe Persistence
> adapter factory before starting the brokerservice.
> It seems that Activemq doesn't recognise it as an XA datasource and tries
> to set autocommit to true in TransactionContext. I think the problem can be
> solved if I can somehow know whether the transaction is XA or not in
> org.apache.activemq.store.jdbc.TransactionContext.
> The question is how can I know that???. Or is there any other better way
> to solve it?
>
>
> On 9/20/07, anish pathadan <an...@gmail.com> wrote:
>
> > Hi Hiram,
> > Thanks for that info.I used the default derby database.I will try
> > creating an XA datasouce and using it.
> >
> > On 9/20/07, Hiram Chirino <hiram@hiramchirino.com > wrote:
> > >
> > > How did you configure the ActiveMQ datasource?  It's data source
> > > should be setup as an XA datasource.
> > >
> > > On 9/20/07, anish pathadan <an...@gmail.com> wrote:
> > > > Hi All,
> > > >        I am trying to send messages to active mq within an XA
> > > transaction. I
> > > > used jdbc persistence and VM connector. When tried to send message I
> > > am
> > > > getting an error "unable to set autocommit on within an XA
> > > > transaction". This is what I find out after the analysis.
> > > >
> > > > org.apache.activemq.store.jdbc.TransactionContext's getConnection()
> > > and
> > > > close() methods tries to set autocommit ON on the jdbc connection.
> > > This will
> > > > cause the above said exception because getConnection() and close()
> > > method is
> > > > called within an XA transaction. There is check in this method to
> > > see
> > > > whether the method is called within a transaction or not. But the
> > > variable
> > > > is having incorrect value when called within an XA transaction.
> > > >
> > > > My question is how can I determine whether the method is called
> > > within an XA
> > > > transaction or not?. Or is there any otherway to solve this issue?
> > > > Best Regards,
> > > > Anish Pathadan
> > > >
> > >
> > >
> > > --
> > > Regards,
> > > Hiram
> > >
> > > Blog: http://hiramchirino.com
> > >
> >
> >
> >
> > --
> > Best Regards,
> > Anish Pathadan
>
>
>
>
> --
> Best Regards,
> Anish Pathadan




-- 
Best Regards,
Anish Pathadan

Re: Help! Unable to send messages to activemq from an XA transaction

Posted by anish pathadan <an...@gmail.com>.
Hi
   The problem happens only if I use an external XA datasource.I used XA
datasource created in geronimo.This datasource is set inthe Persistence
adapter factory before starting the brokerservice.
It seems that Activemq doesn't recognise it as an XA datasource and tries to
set autocommit to true in TransactionContext. I think the problem can be
solved if I can somehow know whether the transaction is XA or not in
org.apache.activemq.store.jdbc.TransactionContext.
The question is how can I know that???. Or is there any other better way to
solve it?


On 9/20/07, anish pathadan <an...@gmail.com> wrote:

> Hi Hiram,
> Thanks for that info.I used the default derby database.I will try creating
> an XA datasouce and using it.
>
> On 9/20/07, Hiram Chirino <hi...@hiramchirino.com> wrote:
> >
> > How did you configure the ActiveMQ datasource?  It's data source
> > should be setup as an XA datasource.
> >
> > On 9/20/07, anish pathadan <an...@gmail.com> wrote:
> > > Hi All,
> > >        I am trying to send messages to active mq within an XA
> > transaction. I
> > > used jdbc persistence and VM connector. When tried to send message I
> > am
> > > getting an error "unable to set autocommit on within an XA
> > > transaction". This is what I find out after the analysis.
> > >
> > > org.apache.activemq.store.jdbc.TransactionContext's getConnection()
> > and
> > > close() methods tries to set autocommit ON on the jdbc connection.
> > This will
> > > cause the above said exception because getConnection() and close()
> > method is
> > > called within an XA transaction. There is check in this method to see
> > > whether the method is called within a transaction or not. But the
> > variable
> > > is having incorrect value when called within an XA transaction.
> > >
> > > My question is how can I determine whether the method is called within
> > an XA
> > > transaction or not?. Or is there any otherway to solve this issue?
> > > Best Regards,
> > > Anish Pathadan
> > >
> >
> >
> > --
> > Regards,
> > Hiram
> >
> > Blog: http://hiramchirino.com
> >
>
>
>
> --
> Best Regards,
> Anish Pathadan




-- 
Best Regards,
Anish Pathadan

Re: Help! Unable to send messages to activemq from an XA transaction

Posted by anish pathadan <an...@gmail.com>.
Hi Hiram,
Thanks for that info.I used the default derby database.I will try creating
an XA datasouce and using it.

On 9/20/07, Hiram Chirino <hi...@hiramchirino.com> wrote:
>
> How did you configure the ActiveMQ datasource?  It's data source
> should be setup as an XA datasource.
>
> On 9/20/07, anish pathadan <an...@gmail.com> wrote:
> > Hi All,
> >        I am trying to send messages to active mq within an XA
> transaction. I
> > used jdbc persistence and VM connector. When tried to send message I am
> > getting an error "unable to set autocommit on within an XA
> > transaction". This is what I find out after the analysis.
> >
> > org.apache.activemq.store.jdbc.TransactionContext's getConnection() and
> > close() methods tries to set autocommit ON on the jdbc connection. This
> will
> > cause the above said exception because getConnection() and close()
> method is
> > called within an XA transaction. There is check in this method to see
> > whether the method is called within a transaction or not. But the
> variable
> > is having incorrect value when called within an XA transaction.
> >
> > My question is how can I determine whether the method is called within
> an XA
> > transaction or not?. Or is there any otherway to solve this issue?
> > Best Regards,
> > Anish Pathadan
> >
>
>
> --
> Regards,
> Hiram
>
> Blog: http://hiramchirino.com
>



-- 
Best Regards,
Anish Pathadan

Re: Help! Unable to send messages to activemq from an XA transaction

Posted by Hiram Chirino <hi...@hiramchirino.com>.
How did you configure the ActiveMQ datasource?  It's data source
should be setup as an XA datasource.

On 9/20/07, anish pathadan <an...@gmail.com> wrote:
> Hi All,
>        I am trying to send messages to active mq within an XA transaction. I
> used jdbc persistence and VM connector. When tried to send message I am
> getting an error "unable to set autocommit on within an XA
> transaction". This is what I find out after the analysis.
>
> org.apache.activemq.store.jdbc.TransactionContext's getConnection() and
> close() methods tries to set autocommit ON on the jdbc connection. This will
> cause the above said exception because getConnection() and close() method is
> called within an XA transaction. There is check in this method to see
> whether the method is called within a transaction or not. But the variable
> is having incorrect value when called within an XA transaction.
>
> My question is how can I determine whether the method is called within an XA
> transaction or not?. Or is there any otherway to solve this issue?
> Best Regards,
> Anish Pathadan
>


-- 
Regards,
Hiram

Blog: http://hiramchirino.com