4 Replies Latest reply on Jul 14, 2005 3:32 AM by pjw

    Clustered HASingleton MDB?

      Hi,

      I have been looking at the documentation on the Wiki for Singleton Message Driven Beans (MDBs) and for HASingletons but I have not found anything showing how to combine the two, i.e. set up a clustered HASingleton MDB.

      I believe that this feature is available in EJB 3.0 ( http://www.jboss.org/products/ejb3) with the @Service and @Clustered annotations, however I am uncomfortable using EJB 3.0 for a production system until the specification has been standardised and until the JBoss implementation is a proper release that has been widely adopted, rather than a preview.

      So, if I don't use EJB 3.0 is there a way to do what I want? i.e. configure a singleton MDB across a whole cluster, rather than just a singleton across a JVM?

      For example, is there a way to configure Message Driven Beans so that they are only created for and connect to queues in the local JNDI tree rather than in the HA JNDI tree? Is there a way to make an MDB dependent on the (HA) JMS service so that it only starts up on the same (local) JVM?

      Or should I just try to configure a .sar service archive deployed into the deploy-hasingleton directory, configured with a QueueReceiver? (This is what I am going to try to do now)

      In which case, do I need to use an MBean configured with the HASingletonController? i.e. can I just drop a simple .sar service archive into the deploy-hasingleton directory and have it automagically be configured as a HASingleton? (These last questions may be better answered in the clustering forum.)

      Thanks for any help,

      Rohan

        • 1. Clustered Message Driven Beans

          Hi,

          I managed to get a HASingleton (i.e. cluster-wide singleton) QueueReceiver to work (instead of an cluster-wide singleton MDB, which did not appear possible).

          I have another problem now:

          When the HASingleton JMS server fails over to another JBoss instance, is it possible to configure Message Driven Beans on multiple JBoss servers in the cluster to automatically reconnect their (Queue)Connection to the new JBoss instance?

          Right now I'm getting the infamous "ping timeout" exception every minute or so:

          java.io.IOException: ping timeout.
           at org.jboss.mq.Connection$PingTask.run(Connection.java:1377)
           at EDU.oswego.cs.dl.util.concurrent.ClockDaemon$RunLoop.run(ClockDaemon.java:364)
           at java.lang.Thread.run(Thread.java:595)


          This is even with specifying the HA-JNDI port of 1100. Actually this is the default in jboss-4.0.1sp1/server/all/deploy/jms/hajndi-jms-ds.xml

          If I had a handle to the Connection used by the Message Driven Bean I could call setExceptionListener() to reconnect when the HASingleton JMS server moves but because the connection is not exposed by the container (or probably more accurately by the EJB 2.0 specification) I don't think this is possible to do in the MDB code.

          I have looked at some of the JBoss 4.0.1sp1 code relating to JMS and Connections etc, but I can't see anything that indicates that a ping timeout exception will be caught and the Connection recreated.

          Am I missing something?

          Is it at all possible to configure this via MDB deployment descriptors or in the standardjboss.xml or deploy/jms/hajndi-jms-ds.xml files?

          Any help appreciated.

          Thanks,

          Rohan

          • 2. Catching onException() for MDBs

            Hi,

            This is just a follow up message. Since I received an email asking what I did about this, I thought it would be better to share it on the forum.

            If I had a handle to the Connection used by the Message Driven Bean I could call setExceptionListener() to reconnect when the HASingleton JMS server moves but because the connection is not exposed by the container (or probably more accurately by the EJB 2.0 specification) I don't think this is possible to do in the MDB code.

            I have looked at some of the JBoss 4.0.1sp1 code relating to JMS and Connections etc, but I can't see anything that indicates that a ping timeout exception will be caught and the Connection recreated.
            ...
            Is it at all possible to configure this via MDB deployment descriptors or in the standardjboss.xml or deploy/jms/hajndi-jms-ds.xml files?


            I was not able to work out how to do this for Message Driven Beans. I did look very briefly at ActiveMQ and was told on the ActiveMQ mailing list that ActiveMQ driven MDBs reconnect to the server after a JMS broker restart.

            However after discussions with our technical architect, we decided to keep it simple (for now) and stick with JBossMQ (rather than introducing yet another software package), although I changed the MDBs into slightly more complex JBoss services that had QueueReceivers that polled the JMS queues.

            This meant that I had more control over the connection and could call setExceptionListener() and handle the exceptions whenever the JMS broker moved to another JBoss instance (and so reconnect appropriately).

            One thing I found necessary to do before reconnecting, was to close() and stop() the old connection before getting a new connection, otherwise I continued to see 'ping timeout' being logged from the old connection.

            This now works very well for us. It is a pity I couldn't get it to work with MDBs as they are simpler to deal with.

            Again, if anyone knows how to do this with MDBs (and JBossMQ) with code and/or deployment descriptors, please let me know, although it is a little late as I have already changed my code as I mentioned above.

            Regards,

            Rohan


            • 3. Re: Catching onException() for MDBs
              pjw

              Hello Rohan,
              a follow-up to your follow-up...

              "Rohan Talip" wrote:

              One thing I found necessary to do before reconnecting, was to close() and stop() the old connection before getting a new connection, otherwise I continued to see 'ping timeout' being logged from the old connection.


              Assume you close() your connection and when trying to get a new connection, you are not able to do so, e.g. because of a permanent connection problem.

              Will this result in a lost connection and a lost ExceptionHandler? Which again means you will not be able to receive any onException()-messages and then again not be able to handle this correctly and establish a new connection?

              cheers,
              pj


              • 4. Re: Clustered HASingleton MDB?
                pjw

                hello,
                to answer my own question: close() on the connection does disable the ExceptionListener. No more onException() will be received. This should not be a problem, however, as we now know the state of the connection and can e.g. spawn a Thread which can periodically try to establish a new connection.

                cheers,
                pj