users@glassfish.java.net

Re: InitialContext on remote server

From: <glassfish_at_javadesktop.org>
Date: Wed, 10 Dec 2008 08:15:59 PST

I filed the bug report and received some excellent help from Ramesh.

The problem it seems is that there are some issues with the JMS service. By default, the type is set to EMBEDDED, this needs to be changed to LOCAL. From the console tree, Configuration->Java Message Service. A server restart is needed. Next, configure the servers as follows:

Server 1 (domain1) - "local"
JMS Connection Factory: jms/MyFactory
JMS Destination: jms/MyTopic
Stateless Session Bean
-------------------------------------------------
Context ic = new InitialContext();

ConnectionFactory connectionFactory = (ConnectionFactory)(ic.lookup("jms/MyFactory"));
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) ic.lookup("jms/MyTopic");
MessageProducer producer = session.createProducer(topic);
TextMessage message = session.createTextMessage();
message.setText(msg);
producer.send(message);




Server2 (domain2) - "remote"
JMS Connection Factory: jms/MyFactory (Property: AddressList Value: server1:xxxx where xxxx is the JMS port of server 1 - see domain.xml)
JMS Destination: jms/MyTopic
LIfecycle Module
------------------------------------------
Context ic = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory)(ic.lookup("jms/MyFactory"));
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) ic.lookup("jms/MyTopic");
MessageConsumer messageConsumer = session.createConsumer(topic);
connection.start();
Message m = messageConsumer.receive();

While this is a good solution, the original "bug" is still unanswered. I would like to be able to "lookup" via JNDI a remote ConnectionFactory rather than create a new factory each time a server is added to the network. I am looking forward to your solution. Thanks again Ramesh!
[Message sent by forum member 'janchj' (janchj)]

http://forums.java.net/jive/thread.jspa?messageID=321041