6 Replies Latest reply on Oct 10, 2008 5:29 PM by clebert.suconic

    JmsTemplate w/ JBM still discouraged?

    thundersmurf

      Are the statements made at

      http://wiki.jboss.org/wiki/JBMSpringJMSTemplateNotes

      still relevant to Spring release 2.5.4?

      The topic of the page is discouraging the use of Spring JMSTemplate with JBoss Messaging but the version of Spring is not referenced.

      tia

      ts.

        • 1. Re: JmsTemplate w/ JBM still discouraged?
          ataylor

          The problem is not confined to a specific version. As far as I'm aware the JMSTemplate still works in the same way.

          • 2. Re: JmsTemplate w/ JBM still discouraged?
            jmoscato

            From the Spring 2.5.x documentation, it appears that it would be safe to listen for messages using a Spring message driven pojo, a DefaultMessageListenerContainer configured with a JmsTransactionManager, and a container managed connection factory (/JmsXA) .

            Is the above statement correct?

            If this is the case, it would be nice to add this as a suggested solution to the JBMSpringJMSTemplateNotes page that warns against using JmsTemplate with JBoss Messaging.


            • 3. Re: JmsTemplate w/ JBM still discouraged?
              clebert.suconic

               

              it would be nice to add this as a suggested solution to the JBMSpringJMSTemplateNotes page that warns against using JmsTemplate with JBoss Messaging.


              This should be the same on any JMS provider you choose. Creating a Session/Producer on every message send is an anti-pattern , and it will certainly cause performance issues on any JMS server you choose.

              You can use the java://JmsXA connector on JBoss AS also, and on that case SpringJMSTemplate would be using the cached producers from JBAS' JCA and you wouldn't see any performance problem.

              (But if you have a standalone client, you won't have the JCA adaptor available)

              • 4. Re: JmsTemplate w/ JBM still discouraged?
                timfox

                 

                "clebert.suconic@jboss.com" wrote:
                it would be nice to add this as a suggested solution to the JBMSpringJMSTemplateNotes page that warns against using JmsTemplate with JBoss Messaging.


                This should be the same on any JMS provider you choose. Creating a Session/Producer on every message send is an anti-pattern , and it will certainly cause performance issues on any JMS server you choose.

                You can use the java://JmsXA connector on JBoss AS also, and on that case SpringJMSTemplate would be using the cached producers from JBAS' JCA and you wouldn't see any performance problem.


                That's partially correct.

                Using JMSXA only caches sessions, message producers and message consumers are never cached. So using JMSXA will always have a less performance than doing your own sensible consumer/producer management in your own program.

                Having said, that producer creation overhead is pretty small in JBM 1.4 since it only creates objects on the client side. Message consumer creation is much higher since it involves a network round trip.

                There's an even worse issue. If you're creating a consumer each time to receive a message and its non durable on a topic. If there are any messages that arrive on the topic between closing one consumer and creating the next one will appear to be "lost" since there's nothing to consume them.

                Therefore we only recommend using JmsXA for sending messages. For consuming, you will still see issues.

                Please note this is NOT JBoss specific.

                The bottom line, is the Spring JMS template does horrible anti-patterns and you can only work around them to some degree.


                • 5. Re: JmsTemplate w/ JBM still discouraged?
                  timfox

                   

                  "jmoscato" wrote:
                  From the Spring 2.5.x documentation, it appears that it would be safe to listen for messages using a Spring message driven pojo, a DefaultMessageListenerContainer configured with a JmsTransactionManager, and a container managed connection factory (/JmsXA) .

                  Is the above statement correct?



                  I haven't looked in the new Spring code, but if it's still creating a new consumer to receive each message, then, *even if you're using a JCA JMS resource adapter* (e.g. JmsXA in JBoss), that is not safe!

                  The resource adapter will only cache sessions, not consumers. So a new consumer will still be created each time. That means, on a topic with a non durable subscriber, any messages that arrive between one consumer and the next, will appear to be lost.

                  Also each consumer is likely to cache a bunch of messages, so every time you close one they have to be rolled back to the queue.

                  ==> Horribly slow + "Lost" messages




                  • 6. Re: JmsTemplate w/ JBM still discouraged?
                    clebert.suconic

                     

                    Therefore we only recommend using JmsXA for sending messages. For consuming, you will still see issues.


                    I thought the spring template was used only to send messages. It's worse than I thought then :-)