You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by dnn <Da...@ngc.com> on 2010/04/23 15:35:09 UTC

QueueBrowser in XA Transaction?

Is the QueueBrowser designed to be run inside an XA transaction?  I keep
getting the following exception when calling the hasMoreElements() method:

javax.jms.TransactionInProgressException: Cannot commit() inside an
XASession
        at
org.apache.activemq.ActiveMQXASession.commit(ActiveMQXASession.java:80)
        at
org.apache.activemq.ActiveMQQueueBrowser.destroyConsumer(ActiveMQQueueBrowser.java:117)
        at
org.apache.activemq.ActiveMQQueueBrowser.hasMoreElements(ActiveMQQueueBrowser.java:165)
<rest truncated>

That is related to the following code in the
ActiveMQQueueBrowser#destroyConsumer() method:

            if (session.getTransacted()) {
                session.commit();
            }

I'm fairly new to using XA, but it seems to me that the QueueBrowser
shouldn't be calling commit() on its own and instead letting the
TransactionManager commit.  Should I always be using the QueueBrowser in a
local transaction, or am I missing something?

Thanks,
Dan Nawrocki
-- 
View this message in context: http://old.nabble.com/QueueBrowser-in-XA-Transaction--tp28341411p28341411.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: QueueBrowser in XA Transaction?

Posted by dnn <Da...@ngc.com>.

Gary Tully wrote:
> 
> Ah, ok, so that exception is the only way you know that it is not
> working...
> an XASession is transacted so it does require an active XA transaction.
> 
> Best post your entire spring context and maybe post to camel-users who
> will
> be more familiar with the <transacted> tag
> 

I get the first exception when in the destroyConsumer() method, but I am
getting another exception that causes the enumeration.getNextElement() to
return null.  I've documented both of them and included a unit test at
https://issues.apache.org/activemq/browse/AMQ-2712.  I basically copied the
existing JmsQueueBrowserTest, made all the sessions transacted, and added a
test case where no messages are added to the queue.  If I made an error
setting up the transacted sessions, let me know and I can update the unit
test.  I'm not too familiar with the core AMQ API as I have been using JMS.

My Spring setup is:

   <amq:broker id="amqBroker" useJmx="true" start="false"
useJmsPriority="true">
      <!-- pretty standard stuff goes here, has been truncated -->
   </amq:broker>

   <bean id="jmsConnectionFactory"
         class="bitronix.tm.resource.jms.PoolingConnectionFactory"
         destroy-method="close"
         depends-on="amqBroker"
   >
      <property name="uniqueName" value="activemq-xa" />
      <property name="className"
value="org.apache.activemq.ActiveMQXAConnectionFactory" />
      <property name="maxPoolSize" value="1000" />
      <property name="driverProperties">
         <props>
            <prop key="brokerURL">vm://localhost?create=false</prop>
         </props>
      </property>
   </bean>

   <!-- Spring JMS template -->
   <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
      <property name="connectionFactory" ref="jmsConnectionFactory" />
      <property name="sessionTransacted" value="true" />
   </bean>

Going forward, I will simply use a non-XA connection for the QueueBrowser. 
I'll have to manually handle the scenario where another transaction owned by
another process/thread consumes a message after I've browsed it.
-- 
View this message in context: http://old.nabble.com/QueueBrowser-in-XA-Transaction--tp28341411p28344039.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: QueueBrowser in XA Transaction?

Posted by Gary Tully <ga...@gmail.com>.
Ah, ok, so that exception is the only way you know that it is not working...
an XASession is transacted so it does require an active XA transaction.

Best post your entire spring context and maybe post to camel-users who will
be more familiar with the <transacted> tag

On 23 April 2010 15:27, dnn <Da...@ngc.com> wrote:

>
>
> Gary Tully wrote:
> >
> > this seems to be another case of
> > https://issues.apache.org/activemq/browse/AMQ-2659 and you also have a
> > valid
> > use case.
> >
>
> That's certainly an interesting bug, but I don't think it applies to me.
>  An
> XA transaction definitely should have been started.  The camel route that
> start the whole shebang is:
>
> <route>
>   <from uri="timer:test?period=1000 />
>   <transacted />
>   <to uri="myQueueBrowser" />
> </route>
>
> As I understand it, the <transacted/> tag will start a transaction because
> none is currently active for the thread (I'm using PROPAGATION_REQUIRED).
> Inside the myQueueBrowser processor, I am using the following code:
>
>      jmsTemplate.browse( getSourceQueue(), new BrowserCallback()
>      {
>         @Override
>         public Object doInJms( Session session, QueueBrowser browser )
> throws JMSException
>         {
>            Enumeration< ? > e = browser.getEnumeration();
>            while( e.hasMoreElements() )
>            {
>               Object o = e.nextElement();
>               // do some stuff with the message
>            }
>            return null;
>         }
>      } );
>
> Where jmsTemplate is an instance of the Spring JmsTemplate class with
> sessionTransacted=true.  From the Spring code, it appears to be using
> PROPAGATION_REQUIRED, which will join the transaction started in the Camel
> route.
>
> I can post my Spring configuration if anyone thinks it will help.
> --
> View this message in context:
> http://old.nabble.com/QueueBrowser-in-XA-Transaction--tp28341411p28342060.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
http://blog.garytully.com

Open Source Integration
http://fusesource.com

Re: QueueBrowser in XA Transaction?

Posted by dnn <Da...@ngc.com>.

Gary Tully wrote:
> 
> this seems to be another case of
> https://issues.apache.org/activemq/browse/AMQ-2659 and you also have a
> valid
> use case.
> 

That's certainly an interesting bug, but I don't think it applies to me.  An
XA transaction definitely should have been started.  The camel route that
start the whole shebang is:

<route>
   <from uri="timer:test?period=1000 />
   <transacted />
   <to uri="myQueueBrowser" />
</route>

As I understand it, the <transacted/> tag will start a transaction because
none is currently active for the thread (I'm using PROPAGATION_REQUIRED). 
Inside the myQueueBrowser processor, I am using the following code:

      jmsTemplate.browse( getSourceQueue(), new BrowserCallback()
      {
         @Override
         public Object doInJms( Session session, QueueBrowser browser )
throws JMSException
         {
            Enumeration< ? > e = browser.getEnumeration();
            while( e.hasMoreElements() )
            {
               Object o = e.nextElement();
               // do some stuff with the message
            }
            return null;
         }
      } );

Where jmsTemplate is an instance of the Spring JmsTemplate class with
sessionTransacted=true.  From the Spring code, it appears to be using
PROPAGATION_REQUIRED, which will join the transaction started in the Camel
route.

I can post my Spring configuration if anyone thinks it will help.
-- 
View this message in context: http://old.nabble.com/QueueBrowser-in-XA-Transaction--tp28341411p28342060.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: QueueBrowser in XA Transaction?

Posted by Gary Tully <ga...@gmail.com>.
this seems to be another case of
https://issues.apache.org/activemq/browse/AMQ-2659 and you also have a valid
use case.

On 23 April 2010 14:35, dnn <Da...@ngc.com> wrote:

>
> Is the QueueBrowser designed to be run inside an XA transaction?  I keep
> getting the following exception when calling the hasMoreElements() method:
>
> javax.jms.TransactionInProgressException: Cannot commit() inside an
> XASession
>        at
> org.apache.activemq.ActiveMQXASession.commit(ActiveMQXASession.java:80)
>        at
>
> org.apache.activemq.ActiveMQQueueBrowser.destroyConsumer(ActiveMQQueueBrowser.java:117)
>        at
>
> org.apache.activemq.ActiveMQQueueBrowser.hasMoreElements(ActiveMQQueueBrowser.java:165)
> <rest truncated>
>
> That is related to the following code in the
> ActiveMQQueueBrowser#destroyConsumer() method:
>
>            if (session.getTransacted()) {
>                session.commit();
>            }
>
> I'm fairly new to using XA, but it seems to me that the QueueBrowser
> shouldn't be calling commit() on its own and instead letting the
> TransactionManager commit.  Should I always be using the QueueBrowser in a
> local transaction, or am I missing something?
>
> Thanks,
> Dan Nawrocki
> --
> View this message in context:
> http://old.nabble.com/QueueBrowser-in-XA-Transaction--tp28341411p28341411.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
http://blog.garytully.com

Open Source Integration
http://fusesource.com