Please help very urgent
suvankar17 Nov 26, 2002 7:05 AMHi 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(){
 try{
 Properties prop = new Properties();
 prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
 prop.put(Context.PROVIDER_URL,"localhost:1099");
 prop.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
 InitialContext ctx = new InitialContext(prop);
 try{
 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);
 topicSubscriber.setMessageListener(this);
 topicConnection.setExceptionListener(this);
 topicConnection.start();
 System.out.println("Server Has Started");
 }catch(Exception e){e.printStackTrace();}
 }
 public void onMessage(Message msg){
 }
 public void onException(JMSException ex){
 try{
 System.out.println("Server Uncreachable..");
 topicConnection.stop();
 }catch(Exception a){a.printStackTrace();}
 }
 public static void main(String[] args)
 {
 jmsTest jms = new jmsTest();
 }
}
Thanks very much,
Suv
 
    