Results 1 to 5 of 5

Thread: Have set a JmsTransactionManager but get no sessionTransactioned

  1. #1
    Join Date
    Jan 2013
    Posts
    2

    Question Have set a JmsTransactionManager but get no sessionTransactioned

    I confingured my jms-container like this
    Code:
    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    		<property name="brokerURL" value="tcp://localhost:61616"></property>
    	</bean>
    	<bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
    		<property name="connectionFactory" ref="jmsConnectionFactory"></property>
    	</bean>
    <jms:listener-container connection-factory="jmsConnectionFactory" transaction-manager="transactionManager">
    		<jms:listener destination="queue.posp.trxfeedback" ref="pospFeedbackListener"/>
    	</jms:listener-container>
    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. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,148

    Default

    Set acknowledgeMode="transacted".

    You, generally, don't need to provide a JmsTransactionManager, the container will use local transactions on the session.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Jan 2013
    Posts
    2

    Default

    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. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,148

    Default

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

    Code:
    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    May 2011
    Location
    Lithuania
    Posts
    3

    Default

    Hi,


    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 at 02:02 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •