Announcement Announcement Module
No announcement yet.
Using JMSTemplate from within a Message Driven Pojo Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using JMSTemplate from within a Message Driven Pojo

    I have implemented a message splitter that receives a message from one queue and sends it onto two other queues. There are different MessageConverters required for each send, so I am using two different JmsTemplates and the convertAndSend methods.

    The splitter is just a POJO like the rest of my MDPs, except that instead of relying on the MessageListener.defaultResponseDestination property to put response values it uses JmsTemplate directly as described above.

    Is using the JmsTemplate a valid way to do this? Would this bundle the two sends in the same transaction as the receive? (I have set sessionTransacted=true) This section the the Spring reference (Chapter 19) makes it sound like I would need a SessionAwareMessageListener for this.

    "Each message listener invocation will then operate within an active JMS transaction, with message reception rolled back in case of listener execution failure. Sending a response message (via SessionAwareMessageListener) will be part of the same local transaction, but any other resource operations (such as database access) will operate independently."

    Does this mean that I need to implement SessionAwareMessageListener and use the Session directly, invoking my MessageConverters as I need them?

    Any clarity you could provide would be appreciated

    Thanks for your time
    Last edited by calebphillips; Oct 15th, 2007, 02:33 PM.

  • #2
    One option as you mention is to implement the SessionAwareMessageListener interface. Another option would be to configure a JmsTransactionManager on the message listener container, which will allow independent JMS code (such as use of JmsTemplate) to be included within the active JMS transaction.

    Note that it is also possible to specify a JmsTransactionManager as external "transactionManager", providing fully synchronized Spring transactions based on local JMS transactions. The effect is similar to "sessionTransacted" set to "true", the difference being that this external transaction management will also affect independent JMS access code within the service layer (e.g. based on JmsTemplate or TransactionAwareConnectionFactoryProxy), not just direct JMS Session usage in a SessionAwareMessageListener.


    • #3
      Thanks very much, Mike. That snippet from the Javadoc said exactly what I needed to know, in particular that setting the local Spring JmsTransactionManager would allow me to use the JmsTemplate within the same transaction.

      Thanks for pointing that out.