Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Asynchronous Messaging using Spring/JMS/ActiveMQ

  1. #1
    Join Date
    May 2005
    Posts
    3

    Default Asynchronous Messaging using Spring/JMS/ActiveMQ

    Hello,

    I need to integrate JMS in my Spring based application. Initially, I tried using JMSTemplate in Spring 1.1 and ran into issues, so I bought a new book called, 'Pro Spring', which says that Spring 1.1 only supports Synchronous messaging. The book *previews* Spring 1.2 JMS Support.

    As per the instructions in the book, I added various beans such as JmsConnectionFactoryBean, JmsSessionFactoryBean to my application context. I tried using Spring 1.2-RC2, but realized that these classes are NOT available in there! I looked at CVS and I don't see them in there either! Has the implementation of JMS changed since this book was written? Am I not looking at the correct CVS repository? Someone please help!

    I was going thru the archives and saw an email which indicates that ActiveMQ can be integrated using a JCA Container. It directs us to the following url: http://activemq.org/JCA+Container

    Is this the best and preferred way at this time? Do I need Spring 1.2 for this?

    Someone please help.... soon! Thanks.

  2. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Indeed, Spring 1.2 does not ship with any JMS support classes for asynchronous messaging. We do plan to come up with a comprehensive solution there, but have deferred this to the Spring 1.3 timeframe.

    For the time being, you can find those classes that Pro Spring mentions in our sandbox in CVS (sandbox/src directory). It's not clear whether we're ever gonna release them in that fashion, though: Unstead, we intend to find a solution where all you need to implement is a JMS MessageListener, managed as Spring bean (similar to an MDB in an EJB container).

    I would currently recommend either ActiveMQ's JCA container (which should work nicely on Spring 1.1) or traditional MDBs if you need multi-threaded asynchronous reception of JMS messages.

    Juergen

  3. #3
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Of course, you can always use the JMS API directly to create message consumers with a MessageListener. Let your JMS client object receive a ConnectionFactory, create a Connection, create a Session, create a MessageConsumer, set a MessageListener. The FactoryBeans from our sandbox don't do anything else, actually.

    The limitation of this approach (both in case of direct usage and with the FactoryBeans from a sandbox) is that it isn't suitable for concurrent message reception. You'd need to explicitly create multiple Sessions with a MessageConsumer/MessageListener each for this.

    FYI, we have a sophisticated JMS listener solution scheduled for Spring 1.3 (properly supporting concurrent reception, possibly also transactional reception), and are already beginning to get it into shape in our sandbox. Stay tuned for any updates in that area.

    Juergen

  4. #4
    Join Date
    May 2005
    Posts
    3

    Default

    Juergen,

    Thanks for the replies. I tried to use ActiveMQs JCA container, but ran into classpath issues related to the classes in the J2EE.jar file; so I decided to use JMS APIs directly. Everything seems to be working fine now; but I am concerned because you said that this isn't suitable for concurrent message reception. As far as I can tell, my logic *should* work for concurrent messages as well. Can you please quickly review the following code snippets and tell me why this solution will not work in the Multi threading environment?

    (My next option is to use the traditional MDBs, but as far as possible I would like to avoid that).

    Anyway, here's a code snippet from my Consumer class:

    Code:
        // This method will be triggered only once, via init-method="start"
        public void start() throws Exception {
    
            try {
                connection = getJmsConf().getJmsConnectionFactory().createQueueConnection();
                QueueSession session = null;
                QueueReceiver queueReceiver = null;
    
                //TODO: Set appropriate client id
                connection.setClientID("foo");
                connection.start();
    
                session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                Queue queue = session.createQueue(getJmsConf().getQueueName());
                queueReceiver = session.createReceiver(queue);
                queueReceiver.setMessageListener(this);
            }
            catch (Exception ex) {
                logger.error(ex.getMessage());
                throw ex;
            }
        }
    
        // This *light-weight* method delegates processing to a SSB
        public void onMessage(Message message) {
    
            TextMessage txt = (TextMessage) message;
            try {
                String text = txt.getText();
                if (message.getJMSRedelivered()) {
                    logger.error("This message was redelivered:" + text);
                } else {
                    logger.debug("This message is new" + text);
                    MessageDelegate.processMessage(_testUser, text);
                }
                message.acknowledge();
            }
            catch (JMSException e) {
                logger.error("Message processing failed!);
            }
        }
    When a message is received, the MessageDelegate sends it to a Stateless Session Bean EJB for processing.

    As far as I can tell, my 'onMessage' method is thread-safe and it should process messages received concurrently safely. Am I missing something? Your help will be greatly appreciated.

    Thanks.

    - Ajay

  5. #5
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    This looks OK to me in general, but be aware that a single JMS Session will essentially work single-threaded: that is, it will invoke your MessageListener from a single thread. Consequently, your MessageListener won't be invoked concurrently, which might lead to a bottleneck if many corresponding messages arrive in parallel.

    What we will provide in Spring 1.3 is essentially pretty similar what you're setting up there in a programmatic fashion, except that it's gonna use multiple Sessions in parallel (freshly created Sessions or a Session pool), with concurrent delivery to the MessageListener.

    Juergen

  6. #6
    Join Date
    May 2005
    Posts
    3

    Default

    Juergen,

    Thanks for the reply. Your point regarding the MessageListener becoming a *bottleneck* is well taken. For now we will proceed with our solution, and as soon as Spring 1.3 is available, we will switch to the *Multiple Listeners* solution offered by Spring.

    Thanks again!

    - Ajay

    PS: By the way, I would like to point out to everyone that, even though 'Pro Spring' book was not helpful for implementing JMS, it is none the less an EXCELLENT book for anyone who needs introduction of Spring as well as AOP.

  7. #7
    Join Date
    Jun 2005
    Location
    Metro Manila, Philippines
    Posts
    1

    Default

    Hi Juergen and Team:

    Re 1.3 Async JMS, will it be tightly coupled to ActiveMQ or a particular JMS implementation, or will it support any JMS implementation? Or those that provide JCA resource adapters?

    I'm looking at porting a JBossMQ client app to Spring.

  8. #8
    Join Date
    Aug 2004
    Location
    London
    Posts
    164

    Default

    Quote Originally Posted by mparaz
    Hi Juergen and Team:

    Re 1.3 Async JMS, will it be tightly coupled to ActiveMQ or a particular JMS implementation, or will it support any JMS implementation? Or those that provide JCA resource adapters?

    I'm looking at porting a JBossMQ client app to Spring.
    BTW If you're using Spring, then I'd suggest not using JBossMQ - its one of the worst JMS providers around - its very slow and has few features.

    I'd definitely recommend you look at either ActiveMQ or Joram as they are the 2 best OSS providers by far. If you want high performance then ActiveMQ gets the nod; but Joram is a reasonable JMS provider too.
    James Strachan
    ------------------
    Open Source Integration
    Iona

  9. #9

    Default

    Quote Originally Posted by Juergen Hoeller
    Indeed, Spring 1.2 does not ship with any JMS support classes for asynchronous messaging. We do plan to come up with a comprehensive solution there, but have deferred this to the Spring 1.3 timeframe.

    Juergen
    Is there currently any release date for Spring 1.3 ?
    Which solution to you recommend in the meanwhile, to be able to use asynchronous messaging ?

    Thanks,
    Sami Dalouche

  10. #10

    Default

    Quote Originally Posted by samokk
    Which solution to you recommend in the meanwhile, to be able to use asynchronous messaging ?
    Ok, sorry, I saw you already posted the answer in the same thread

Similar Threads

  1. Asynchronous Remoting with Spring and ActiveMQ
    By jpwinans in forum Remoting
    Replies: 2
    Last Post: Sep 21st, 2005, 10:29 AM
  2. Replies: 1
    Last Post: Jun 28th, 2005, 04:32 AM
  3. Asynchronous JMS Support
    By ptruax in forum JMS
    Replies: 4
    Last Post: May 27th, 2005, 11:50 AM
  4. Messaging question
    By tentacle in forum Architecture
    Replies: 6
    Last Post: Dec 20th, 2004, 08:33 AM
  5. Spring and Asynchronous messaging
    By spring04 in forum EJB
    Replies: 4
    Last Post: Dec 16th, 2004, 02:30 PM

Posting Permissions

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