Discussions

General J2EE: Using JMS with Servlets

  1. Using JMS with Servlets (5 messages)

    I have a requirement wherein the input coming in is a JMS message. One option to use would be an EJB/MDB to handle the message. I was thinking of using a solution which was scalable but not as expensive(cost/performance overhead) as the EJB. I was wondering if the Servlet API had something to offer. In my application, the JMS piece would not be a remote client but be hosted by the same machine which would host the EJB or Servlet.
    Any ideas?

    Thanks

    Ramdas

    Threaded Messages (5)

  2. Using JMS with Servlets[ Go to top ]

    Ramdas,

    I don't think there are any Servlet API's for pulling or receiving a message but a Servlet can be made to receive a message by implementing the javax.jms.MessageListener interface. But then, i am not sure of the performance here. I think MDB's are better designed to handle these scenarios

    cheers
    Satish
  3. Using JMS with Servlets[ Go to top ]

    Hi,

    We use JMS with servlets a lot, but because we're interacting with external systems and webpages, while using JMS for certain internal messaging. But if you don't already need a servlet, and are in the same JVM, I'd go MDB.

    Cheers.
  4. Using JMS with Servlets[ Go to top ]

    Thanks for your replies.
    About using Servlets to implement the MessageListener, I am not sure if that is possible. Looks like using MDBs is a more suitable solution for a JMS message consumer which is scalable.
    But I was wondering, in the absence of MDBs which have come into being since EJB2.0, how did people get around building a scalable message consumer(using Java) other than buying off the shelf messaging products.

    Thanks

    Ramdas
  5. Using JMS with Servlets[ Go to top ]

    Ramdas,

    Before the advent of MDB's, WebLogic used a concept called ServerSideSessionPools for JMS. These pools were assigned to a particular queue or topic. A java class which implements a particular interface was also assigned to it for message consumption. The structure of the java class was roughly similar to MDB's except the benefits of Object pooling and transaction propagation. I am not sure of other application servers providing this mechanism but i think they would have provided something like this.
    Regarding Servlet implementing MessageListener...it is possible, i have seen some sites doing it(for reasons of their own) but i think it is a bad idea

    cheers
    Satish
  6. Apache Messenger[ Go to top ]

    I hope it's not too late. Check out Messenger in the Apache Commons project. I used it and it works great. It's like Message Driven Beans without the EJB overhead.