Results 1 to 3 of 3

Thread: Using JMSTemplate from within a Message Driven Pojo

  1. #1
    Join Date
    Jan 2006
    Location
    Nashville, TN
    Posts
    34

    Default 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 at 01:33 PM.

  2. #2
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    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.

    http://www.springframework.org/docs/...Container.html

    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.
    Mike Bingham

  3. #3
    Join Date
    Jan 2006
    Location
    Nashville, TN
    Posts
    34

    Default

    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.

Posting Permissions

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