Announcement Announcement Module
Collapse
No announcement yet.
Exception thrown when trying to send event using JmsTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception thrown when trying to send event using JmsTemplate

    I have a Jta transaction opened, and I am doing different things inside (like db access within a tx template, etc).
    In case the Jta fails, there will be a rollback on the persistent objects, so that is OK.
    However, at the end, I need to call a method "alarmsChanged" that will invoke an eventBroadcaster which will send an event.
    Because this call to my method "alarmsChanged" is not transaction aware, I need to make sure this method is called only if
    the Jta transaction succeeds. Therefore I registered a Synchronization object with the JtaTransactionManager.
    At the end of the transaction, the following methods on the Synchronization object will be called: "beforeCompletion" and "afterCompletion".
    In the "afterCompletion" I check if the transaction status after completion is STATUS_COMMITTED, and only in this case
    I call my method "alarmsChanged" which calls, as I said before, the eventBroadcaster to send the event.

    I am getting the following exception:



    09:21:23,336 INFO [SingletonInternalAlarmServiceImpl] beforeCompletion called
    09:21:23,339 INFO [SingletonInternalAlarmServiceImpl] afterCompletion called
    09:21:23,339 INFO [SingletonInternalAlarmServiceImpl] afterCompletion Status: STATUS_COMMITTED. calling alarmsChanged
    09:21:23,340 ERROR [JmsSessionFactoryImpl] could not create session
    javax.resource.ResourceException: Transaction is not active: tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=sol-boo/2497, BranchQual=,

    localId=2497]
    at org.jboss.resource.connectionmanager.TxConnectionM anager.getManagedConnection(TxConnectionManager.ja va:290)
    at org.jboss.resource.connectionmanager.BaseConnectio nManager2.allocateConnection(BaseConnectionManager 2.java:396)
    at org.jboss.resource.connectionmanager.BaseConnectio nManager2$ConnectionManagerProxy.allocateConnectio n(BaseConnectionManager2.java:842)
    at org.jboss.resource.adapter.jms.JmsSessionFactoryIm pl.allocateConnection(JmsSessionFactoryImpl.java:3 89)
    at org.jboss.resource.adapter.jms.JmsSessionFactoryIm pl.createSession(JmsSessionFactoryImpl.java:369)
    at org.springframework.jms.support.JmsAccessor.create Session(JmsAccessor.java:200)
    at org.springframework.jms.core.JmsTemplate.access$50 0(JmsTemplate.java:76)
    at org.springframework.jms.core.JmsTemplate$JmsTempla teResourceFactory.createSession(JmsTemplate.java:8 75)
    at org.springframework.jms.connection.ConnectionFacto ryUtils.doGetTransactionalSession(ConnectionFactor yUtils.java:237)
    at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:415)
    at org.springframework.jms.core.JmsTemplate.send(JmsT emplate.java:475)
    at org.springframework.jms.core.JmsTemplate.send(JmsT emplate.java:467)
    at com.test.axs.applications.event.JmsEventBroadcaste rSupport.sendEvent(JmsEventBroadcasterSupport.java :27)
    at com.test.axs.management.event.AbstractEventBroadca sterSupport$EventInvocationHandler.invoke(Abstract EventBroadcasterSupport.java:50)
    at $Proxy226.neAlarmSummaryChanged(Unknown Source)
    --> at com.test.axs.app.alarms.impl.AlarmCounterControlle r.alarmsChanged(AlarmCounterController.java:223)
    at com.test.axs.app.alarms.impl.CompositeAlarmListene r.alarmsChanged(CompositeAlarmListener.java:23)
    at

    com.test.axs.app.alarms.impl.SingletonInternalAlar mServiceImpl$TransientAlarmListenerSynchronization .afterCompletion(SingletonInternalAlarmServiceImpl

    .java:192)
    at org.jboss.tm.TransactionImpl.doAfterCompletion(Tra nsactionImpl.java:1526)
    at org.jboss.tm.TransactionImpl.completeTransaction(T ransactionImpl.java:1198)
    at org.jboss.tm.TransactionImpl.commit(TransactionImp l.java:377)
    at org.jboss.tm.TxManager.commit(TxManager.java:240)
    at org.jboss.tm.usertx.client.ServerVMClientUserTrans action.commit(ServerVMClientUserTransaction.java:1 40)
    at org.springframework.transaction.jta.JtaTransaction Manager.doCommit(JtaTransactionManager.java:842)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:651)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:621)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.commitTransactionAfterReturning (TransactionAspectSupport.java:311)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:117)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :161)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy157.executeAlarmResynchronization(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor341.invoke(Unkn own Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java :36)
    at sun.reflect.GeneratedMethodAccessor91.invoke(Unkno wn Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java :239)
    at javax.management.modelmbean.RequiredModelMBean.inv okeMethod(RequiredModelMBean.java:1071)
    at javax.management.modelmbean.RequiredModelMBean.inv oke(RequiredModelMBean.java:953)
    at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDy namicInvoker.java:164)
    at org.jboss.mx.modelmbean.RequiredModelMBeanInvoker. invoke(RequiredModelMBeanInvoker.java:127)
    at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanSe rverImpl.java:659)
    at org.jboss.system.server.jmx.LazyMBeanServer.invoke (LazyMBeanServer.java:279)
    at org.jboss.mx.util.JMXInvocationHandler.invoke(JMXI nvocationHandler.java:287)
    at $Proxy214.executeAlarmResynchronization(Unknown Source)
    at com.test.axs.app.alarms.AlarmSynchronisationJob.ex ecute(AlarmSynchronisationJob.java:40)
    at com.test.axs.container.jobmanager.ManagedJob.run(M anagedJob.java:45)
    at com.test.axs.container.jobmanager.JMSJobExecutor.o nMessage(JMSJobExecutor.java:27)
    at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doInvokeListener(AbstractMessageLi stenerContainer.java:505)
    at org.springframework.jms.listener.AbstractMessageLi stenerContainer.invokeListener(AbstractMessageList enerContainer.java:444)
    at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doExecuteListener(AbstractMessageL istenerContainer.java:414)
    at

    org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.doReceiveAndExecute(Abstrac tPollingMessageListenerContainer.java:293)
    at

    org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.receiveAndExecute(AbstractP ollingMessageListenerContainer.java:239)
    at

    org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.invokeL istener(DefaultMessageListenerContainer.java:872)
    at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.run(Def aultMessageListenerContainer.java:812)
    at java.lang.Thread.run(Thread.java:595)



    The error says that the transaction is not active which is true, because it was commited.
    I supposed that the eventBroadcaster, which is using a JmsTemplate to send messages, was looking for the Jta transaction. So I changed the code.
    The original code was:

    <bean id="eventBroadcaster" class="com.test.axs.applications.event.JmsEventBro adcasterSupport">
    <constructor-arg
    value="com.test.axs.app.alarms.clientapi.AlarmServ iceListener" />
    <constructor-arg ref="jmsTemplate" />
    </bean>

    <bean id="jmsTemplate"
    class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
    <ref bean="jmsQueueConnectionFactory" />
    </property>
    <property name="defaultDestination">
    <ref bean="destination" />
    </property>
    <property name="receiveTimeout">
    <value>30000</value>
    </property>
    </bean>

    <jee:jndi-lookup id="jmsQueueConnectionFactory" jndi-name="TopicXAConnectionFactory"/>


    So I changed the code (notice the only change was to add sessionTransacted=true to use local transaction) as follows:

    <bean id="eventBroadcaster" class="com.test.axs.applications.event.JmsEventBro adcasterSupport">
    <constructor-arg
    value="com.test.axs.app.alarms.clientapi.AlarmServ iceListener" />
    <constructor-arg ref="jmsTemplate" />
    </bean>

    <bean id="jmsTemplate"
    class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
    <ref bean="jmsQueueConnectionFactory" />
    </property>
    <property name="defaultDestination">
    <ref bean="destination" />
    </property>
    <property name="receiveTimeout">
    <value>30000</value>
    </property>
    <property name="sessionTransacted">
    <value>true</value>
    </property>

    </bean>

    <jee:jndi-lookup id="jmsQueueConnectionFactory" jndi-name="TopicXAConnectionFactory"/>


    The ideea is to use local resource transaction, not to look for the Jta tx. But I still get the same error...

  • #2
    found the solution

    I found the solution: just setting the sessionTransacted=true in the JmsTemplate was not enuogh. Somehow, JMS does not open a short lived local tx.
    So I inserted a transaction template around the event broadcaster. The trick is also to detach the tx template from the global Jta by setting the propagationBehaviour=PROPAGATION_REQUIRES_NEW.

    Comment

    Working...
    X