4 Replies Latest reply on Oct 30, 2002 12:31 PM by Terry Rosenbaum


    suvankar Newbie

      I m running Jboss-3.0.0 and I have a topic called testTopic and there are different applications, who in time to time publishes diffent messages on this testTopic.
      I have one client who is subscribed once with this testTopic and keeps listenning for any message on that topic and whenever there is some message on that topic, the client picks that message up displays it. Now my problem is if i shutdown the Jboss server, how will the client detect that the server has gone down, so that the client can throw a message saying server has gone down and whenever the server is up again, the client reconnects and throws a message the server is up again, and the client starts receiving messages again....

      Please help, this is very urgent....

      Thanks in advance,

        • 1. Re: PLSSSS HELP,   ITS URGENT
          Adrian Brock Master

          MyExceptionListener l = new MyExceptionListener();

          public class MyExceptionListener
          implements javax.jms.ExceptionListener
          public void onException(JMSException e)
          // Handle the problem here


          • 2. Re: PLSSSS HELP,   ITS URGENT
            suvankar Newbie

            Thank you so much adrian, I hope your approach will definitely work, thank you so much for your kind help.


            • 3. Re: PLSSSS HELP,   ITS URGENT
              suvankar Newbie

              I tried the aprroach mentioned and accordingly when the server goes down, the onException method gets called and so the client knows about the server is down, but now the problem is that when the server goes up, the client cannot reconnect to the JMS provided, it still shows the exception that server is unreachable, so how can i recconnect my client to the server , so that normal communication is resumed again.

              My test code is shown below:-

              import javax.jms.*;
              import java.util.*;
              import javax.naming.*;
              public class jmsTest implements MessageListener
              TopicConnectionFactory topicConnectionFactory = null;
              TopicConnection topicConnection = null;
              TopicSession topicSession = null;
              Topic topic = null;
              TopicSubscriber topicSubscriber = null;
              public jmsTest(){
              public static void main(String[] args)
              jmsTest jms = new jmsTest();
              public void onMessage(Message aMessage){
              System.out.println("On Message is called");
              public void setupJMS(){
              Properties prop = new Properties();

              InitialContext ctx = new InitialContext(prop);

              topicConnectionFactory = null;
              topicConnection = null;
              topicSession = null;
              topic = null;
              topicSubscriber = null;

              topicConnectionFactory = (TopicConnectionFactory)ctx.lookup("ConnectionFactory");
              topic = (Topic)ctx.lookup("topic/aTopic");
              topicConnection = topicConnectionFactory.createTopicConnection();
              topicSession = topicConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
              topicSubscriber = topicSession.createSubscriber(topic);
              MyExceptionListener l = new MyExceptionListener();
              System.out.println("Connected with the server");
              }catch(Exception a){ System.out.println("Could not establish JMS with server: " + a.toString());}

              private class MyExceptionListener implements javax.jms.ExceptionListener{
              public void onException(JMSException e){

              System.out.println("Error:" + e.toString());

              System.out.println("Checking server for live..");
              System.out.println("Connected again with the server..");
              }catch(Exception a){System.out.println("Server is out of reach...");}


              Please help...


              • 4. Re: PLSSSS HELP,   ITS URGENT
                Terry Rosenbaum Newbie

                I'm not sure if the Topic object will
                remain valid across server reboot. You'll
                have to discover that for yourself. I fairly sure
                that the TopiConnection, TopicSession,
                and TopicSubscriber will all be invalid
                after the server goes down.

                Thus, after detecting the server failure
                in your exception listener, you probably need
                to do:

                1) close the TopicSubscriber
                2) close the TopicSession
                3) close the TopicConnection
                4) recreate the TopicConnection
                5) start the topic connection
                6) recreate the TopicSession
                7) recreate the TopicSubscriber

                At step 4) and 5), keep trying while errors occur
                until successful before proceeding to step 6).