Remote JMS connection still using localhost

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-03-26T08:26:47Z Indexed on 2010/03/26 8:33 UTC
Read the original article Hit count: 470

Filed under:
|
|

I have a created a JMS Connection Factory on a remote glassfish server and want to use that server from a java client app on my local machine. I have the following configuration to get the context and connection factory:

Properties env = new Properties();
env.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
env.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
env.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
env.setProperty("org.omg.CORBA.ORBInitialHost", JMS_SERVER_NAME);
env.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

initialContext = new InitialContext(env);
TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) initialContext.lookup("jms/MyConnectionFactory");
topicConnection =  topicConnectionFactory.createTopicConnection();

topicConnection.start();

This seems to work and when I delete the ConnectionFactory from the glassfish server I get a exception indicating that is can't find jms/MyConnectionFactory as expected.

However when I subsequently use my topicConnection to get a topic it tries to connect to localhost:7676 (this fails as I am not running glassfish locally).

If I dynamically create a topic:

TopicSession pubSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = pubSession.createTopic(topicName);
TopicPublisher publisher = pubSession.createPublisher(topic);
Message mapMessage = pubSession.createTextMessage(message);
publisher.publish(mapMessage);

and the glassfish server is not running locally I get the same connection refused however, if I start my local glassfish server the topics are created locally and I can see them in the glassfish admin console.

In case you ask I do not have jms/MyConnectionFactory on my local glassfish instance, it is only available on the remote server.

I can't see what I am doing wrong here and why it is trying to use localhost at all.

Any ideas?

Cheers,

James

© Stack Overflow or respective owner

Related posts about glassfish

Related posts about jms