Problem looking up ConnectionFactory on JBoss restart
pat.ryan Dec 8, 2002 3:35 PMHi Everyone,
I am using JBoss3.0.4 with jdk1.4.1
I have a simple test application with 2 jms clients using the topic/testTopic. If I start JBoss followed by the clients everything seems to run well.
My problems come about when I try to make it tolerant of JBoss server restarts.
If I stop / start JBoss, I have code in place which I thought would re-initialize the connection to JBoss. However I keep seeing the following exception in org.jnp.interfaces.NamingContext.lookUp line 466 in my debugger:
java.rmi.ConnectException
detail = java.net.ConnectException
detailMessage = Connection refused: connect
detailMessage = Connection refused to host: <my IP addr where jboss is running which happens to be local >
Below are the methods I use to create the connection,sessions, etc as well as the onException method. The BOLD line below is the line that keeps failing.
private void setupPubSub() throws Exception {
try {
try {
// closing the connection will close all constituent objects...
if( connection != null ) connection.close();
} catch (JMSException e) {
}
Properties env = new Properties();
// java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
// java.naming.provider.url=jnp://localhost:1099
// java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
env.put(
"java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.provider.url", "jnp://DSI1:1099");
env.put(
"java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
jndi = new InitialContext(env);
Object tmp = jndi.lookup("ConnectionFactory");
if( tmp == null ) throw new Exception("Could NOT lookup ConnectionFactory from jndi IntialContext");
// jms topic connection factory - you can type cast this to a QueueConnectionFactory as well
TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
// Get a connection to the JMS service from the connection factory
// all publishers and subscribers from this application can use the same connection
connection = tcf.createTopicConnection(); // could take a username and password
connection.setExceptionListener(this);
// create a session for publishing and a session for subscribing
pubSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
subSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
// Look up JMS Topic
Topic topic = (Topic) jndi.lookup("topic/testTopic");
// Create a JMS Publisher
publisher = pubSession.createPublisher(topic);
// Create a subscriber
TopicSubscriber subscriber = subSession.createSubscriber(topic, null, true);
subscriber.setMessageListener(this);
// start the connection - must be the last step
connection.start();
initialized = true;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public void onException(JMSException e) {
System.out.println("@@@@@ On Exception called: " + e.getMessage());
System.out.println("Trying to setup PubSub again...");
try {
setupPubSub();
} catch (Exception e1) {
System.out.println("in OnException setupPubSub threw exception: " + e1.getMessage());
}
}
If anyone has any suggestions I sure would appreciate it.