9 Replies Latest reply on Jun 11, 2003 1:46 PM by mikeklem

    Reconnect after dropped connection

    ccanning

      Hi,

      I am writing to see if there is any reason why JBoss MQ doesn't try to reconnect to a queue when the connection is lost. Why does it continually ping, throw IOExceptions, but not try to reconnect? Is this an oversite, a bug, or a feature? I would appreciate if someone could provide some information so I can decide whether to implement the feature or find a way to work around it. Oh yeah, we are using JBoss3.0.6. Thanks.

      Chuck

        • 1. Re: Reconnect after dropped connection
          sashahunt

          Hi,

          I don't know if/why JBossMQ does or doesn't automatically connect. I wouldn't expect it to.
          But couldn't you use the "onException"
          functionality to reconnect?



          • 2. Re: Reconnect after dropped connection
            delboypass

            Im chasing the same problem.

            We have a bean that creates everything on its setup. connectionfactory ect...

            Then we can take the server down so it loses the connection.

            When we run the testclient that sends a message through the bean all the information is still available but since the server is down it cant send. But every minute the mq tries to connect with asyncr.ping.

            Even when the server comes back up, it still doesnt connect.
            Is it meant to be able to connect???

            • 3. Re: Reconnect after dropped connection

              I have been dealing with the same issue. I included an example I used to write my reconnect code. It works, I just wonder if there is a better way to do this.

              I create a thread in my onException method that is used to continuously attempt to reconnect to the JMS server.

              I hope this helps others since it this seems to be an issue.

              • 4. Re: Reconnect after dropped connection

                BTW: I am using 3.0.7.

                In my previous post, my source code uses the SampleUtilities.java class from Sun's site. It can be found here:

                http://java.sun.com/products/jms/tutorial/1_3_1-fcs/examples/appendix/SampleUtilities.java

                Here's what I discovered while figuring out how to reconnect.

                1. Close your jms connection object.

                2. After you reconnect, you have to also re-create your session and listener objects.

                • 5. Re: Reconnect after dropped connection
                  leathurman

                  Hi Mike,

                  Found your reply very interesting but it exhibits the same problems as my own i.e the connectionFactory is null on reconnect.

                  What IL are you using? I am currently on 3.0.4 so maybe that is the issues.

                  Regards
                  Lea.

                  • 6. Re: Reconnect after dropped connection

                    Iam using JBoss 3.0.7.

                    You need to rebuild your connectionFactory when reconnecting. That is what I did, I believe. I just rebuilt everything until it worked.

                    • 7. Re: Reconnect after dropped connection
                      leathurman

                      Hi Mike,

                      Yes I do rebuild everything.

                      while(queueConnection == null){

                      try {
                      InitialContext initialContext = new InitialContext();
                      connectionFactory =
                      (QueueConnectionFactory)(initialContext.lookup(DEFAULT_JMS_QUEUE_CONN_FACTORY));

                      if (connectionFactory != null) {

                      // Under certain circumstances ic lookup succeeds but returns a null
                      // connectionFactory.
                      queueConnection = connectionFactory.createQueueConnection();
                      queueConnection.setExceptionListener(this);
                      Queue queue = (Queue)(initialContext.lookup(this.queueName));

                      queueSession =
                      queueConnection.createQueueSession(
                      false,
                      QueueSession.AUTO_ACKNOWLEDGE);

                      queueReceiver = queueSession.createReceiver(queue);
                      queueReceiver.setMessageListener(new JMSListener());
                      queueConnection.start();
                      }
                      }

                      Your post also exhibited the same behaviour. It must be 3.0.4 that is causing it. I am going upto 3.2.1 so will try again.

                      Lea.

                      • 8. Re: Reconnect after dropped connection
                        leathurman

                        Mike,

                        Just upgraded to 3.0.7 and I get the exact same with your code.

                        It's as if I have a problem with the initialContext even with building an new initialContext every time.

                        lea

                        • 9. Re: Reconnect after dropped connection

                          I assume you can get the connection factory from JNDI when the server comes up. Otherwise your code would not work. Correct?

                          When I tested this code, I had a simple client app connect to the jms server. Then I stopped the server and restarted it. While the server was restarting, the client continued to reconnect. Once the server was rebooted, my client was able to reconnect.

                          I don't see why you would not be able to get the connection factory even after the server has come back up.

                          I would add more debug statements just to get more info.