1 Reply Latest reply on Nov 27, 2002 2:25 PM by garyg

    Please help very urgent

    suvankar Newbie

      Hi all,
      I have written a very small test consumer. It listens for any message on a particular topic on the jboss-3.0.0 server and when the server goes down for any reason, the test consumer detects the server down through exception listener and prints that. Now what i want is that, whenever the server is restarted, the test consumer should detect it and resume the connection with the server for listening for more messages.... I could not find out how to re start the connection...My code is listed below....

      import javax.jms.*;
      import java.util.*;
      import javax.naming.*;
      public class jmsTest implements MessageListener, javax.jms.ExceptionListener
      static boolean status = true;

      TopicConnectionFactory topicConnectionFactory = null;
      TopicConnection topicConnection = null;
      TopicSession topicSession = null;
      Topic topic = null;
      TopicSubscriber topicSubscriber = null;

      public jmsTest(){

      Properties prop = new Properties();

      InitialContext ctx = new InitialContext(prop);
      topicConnectionFactory = (TopicConnectionFactory)ctx.lookup("ConnectionFactory");
      }catch(Exception b){
      System.out.println("Server Unreachable");

      topicConnection = topicConnectionFactory.createTopicConnection();
      topicSession = topicConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
      topic = (Topic)ctx.lookup("topic/aTopic");
      topicSubscriber = topicSession.createSubscriber(topic);
      System.out.println("Server Has Started");

      }catch(Exception e){e.printStackTrace();}

      public void onMessage(Message msg){
      public void onException(JMSException ex){
      System.out.println("Server Uncreachable..");
      }catch(Exception a){a.printStackTrace();}

      public static void main(String[] args)
      jmsTest jms = new jmsTest();


      Thanks very much,

        • 1. Re: Please help very urgent
          garyg Novice


          If I'm understanding you right, and if your server goes down ... then when your server comes back up just have it recreate the same topic. Now if the client goes down, you can detect if the topic is there by isRegistered() and if it does already exists, either delete it and recreate or just re-use that same topic which I think is ok.

          Just make sure that when your client detects the server going down by printing the exception msg, that it doesn't take any action to stop subscribing.

          Hope that was of help.