Announcement Announcement Module
No announcement yet.
Have set a JmsTransactionManager but get no sessionTransactioned Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Have set a JmsTransactionManager but get no sessionTransactioned

    I confingured my jms-container like this
    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    		<property name="brokerURL" value="tcp://localhost:61616"></property>
    	<bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    		<property name="connectionFactory" ref="jmsConnectionFactory"></property>
    <jms:listener-container connection-factory="jmsConnectionFactory" transaction-manager="transactionManager">
    		<jms:listener destination="queue.posp.trxfeedback" ref="pospFeedbackListener"/>
    but when I throw a IllegalArgumentException in "pospFeedbackListener",no rollback happens,and I trace code find that
    the sessionTransacted is false in AbstractMessageListenerContainer.rollbackOnExcepti onIfNecessary
    How I can get a expect result ?thank a lot

  • #2
    Set acknowledgeMode="transacted".

    You, generally, don't need to provide a JmsTransactionManager, the container will use local transactions on the session.


    • #3
      Refer to spring reference,Setting acknowledgeMode=transacted is the same with providing a transactionManager
      Puzzled much, because I lately will use global transaction with jtaTransactionManager to associate local datasource and jmsssession
      And when I throw a Exception in MsgListenerHandler that deal with the biz, I want they all commit or rollback ,so how can I do ? Thank you.


      • #4
        Right, but when you use the namespace for configuration, the parser sets sessionTransacted when you use ack mode=transacted...

        Integer acknowledgeMode = parseAcknowledgeMode(containerEle, parserContext);
        if (acknowledgeMode != null) {
        	if (acknowledgeMode == Session.SESSION_TRANSACTED) {
        		containerDef.getPropertyValues().add("sessionTransacted", Boolean.TRUE);
        	else {
        		containerDef.getPropertyValues().add("sessionAcknowledgeMode", acknowledgeMode);
        Yes, if you want to synchronize with some other transaction manager (such as JTA, JDBC), then you need to provide a transaction manager. All I was saying was that if you are only using JMS, then you don't usually need to specify a JmsTransactionManager.


        • #5

          transaction-manager="jmsTransactionManager" (not XA TX) vs acknowledge="transacted" (Local TX)

          <jms:listener-container transaction-manager="jmsTransactionManager"> ...
          will bind JMS Session to current thread and invocations on JmsTemplate inside <jms:listener .../> handler method stack (MessageListener.onMessage(Message) or SessionAwareMessageListener.onMessage(M, Session) or POJO method) will get/use exactly same JMS Session (JMS Session from thread).

          <jms:listener-container acknowledge="transacted"> ...
          JMS Session will be transacted and same JMS Session will be provided to e.g. SessionAwareMessageListener.onMessage(M, Session). Invocations on JmsTemplate inside <jms:listener .../> handler method stack in this case will get JMS Session not related to JMS Session created by <jms:listener-container ...>

          Common between two:
          In both cases JMS Session commit will acknowledge JMS Provider about consumed JMS Messages and is synchronized with other transaction managers (eg DataSourceTransactionManager).

          I think this could be useful to know.
          Last edited by lutomas; Feb 7th, 2013, 02:02 PM.