8 Replies Latest reply: Jul 4, 2011 7:28 PM by r035198x RSS

    Why MDB to read a JMS Q

    PraveenAP
      Hi,

      This is more of a conceptual question.

      I have recently learned to configure a JMS queue on the weblogic server.

      I have also learnt to read messages from the JMS queue using an MDB.

      Now my question is, what is the fun in using the MDB, I could use a simple Java Pojo as well right?

      Why should I use MDB??????

      Also any sample to configure Foriegn JMS server would be greatly appreciated.


      Thanks
      Praveen
        • 1. Re: Why MDB to read a JMS Q
          Nigeldeakin-Oracle
          Why should I use MDB??????
          MDBs are not relevant if you want to receive messages synchronously (using MessageConsumer.receive().

          But if you want to receive messages asynchronously in a Java EE EJB or Web container you don't have any choice: you need to use a MDB. The Java EE spec doesn't allow you to do it any other way.
          Also any sample to configure Foriegn JMS server would be greatly appreciated.
          Please ask each question in a separate thread.

          In this case, ask in the WebLogic JMS forum at
          WebLogic Server - JMS

          Nigel
          • 2. Re: Why MDB to read a JMS Q
            452196
            Obviously your message handling has to be part of some kind of Java application. An MDB can run under an application server just to act on messages.

            But that doesn't mean you can't handle messages as part of a stand-alone daemon, or as part of a web application to which it's relevant, for example.

            Nearly all my message handlers, so far, have been handled by stand alone applications, we don't bother with application servers these days. I do have one case where a web application listens for a message telling it that the database has been updated in batch, so it should flush it's cache.

            In some cases that's the sole function of the program, in others it just triggers an update of the data that a user is looking at.
            • 3. Re: Why MDB to read a JMS Q
              r035198x
              user10583423 wrote:
              Why should I use MDB??????
              Thanks
              Praveen
              The integration with an EE container gives you spec defined container management of transactions and connection pooling.
              • 4. Re: Why MDB to read a JMS Q
                452196
                r035198x wrote:
                >
                The integration with an EE container gives you spec defined container management of transactions and connection pooling.
                So, at least theoretically, does Spring.
                • 5. Re: Why MDB to read a JMS Q
                  r035198x
                  malcolmmc wrote:
                  r035198x wrote:
                  >
                  The integration with an EE container gives you spec defined container management of transactions and connection pooling.
                  So, at least theoretically, does Spring.
                  I don't follow. How did we get from your question to here?
                  Are you saying that because you can do this in Spring means that you should not use MDBs?
                  I'm just failing to see the connection/logic here.
                  • 6. Re: Why MDB to read a JMS Q
                    gimbal2
                    user10583423 wrote:
                    Now my question is, what is the fun in using the MDB, I could use a simple Java Pojo as well right?
                    - MDB is the link between JEE and JMS; JMS is the implementation of a messaging standard. So the ability to easily use JMS and therefor support messaging in your application is one reason.
                    - MDB execution is asynchronous
                    - MDB execution can be part of a container managed transaction
                    - MDB architecture fits really well to make otherwise unrelated applications and components communicate with each other without having to add another layer of complexity in the usage of SOAP or REST type services.

                    For a nice example of what JMS can be used for, check out how it is used in the last.fm website.

                    http://java.dzone.com/articles/case-study-how-lastfm-uses
                    • 7. Re: Why MDB to read a JMS Q
                      452196
                      r035198x wrote:
                      Are you saying that because you can do this in Spring means that you should not use MDBs?
                      I'm saying that if you don't need the hassle of a full-scale application server for something else it's not worth having one just to support MDBs.

                      That you can be as pooled, as asynchronous etc. as you like without them.
                      • 8. Re: Why MDB to read a JMS Q
                        r035198x
                        malcolmmc wrote:
                        r035198x wrote:
                        Are you saying that because you can do this in Spring means that you should not use MDBs?
                        I'm saying that if you don't need the hassle of a full-scale application server for something else it's not worth having one just to support MDBs.

                        That you can be as pooled, as asynchronous etc. as you like without them.
                        These days you don't need to a full scale application server as most container providers are already splitting functionality into pluggable 'profiles'.