Skip to main content

Issue connecting to a remote JMS queue from standalone client

1 reply [Last post]
sirishvadala
Offline
Joined: 2012-04-19
Points: 0

I had already posted this issue in JMS Forum and was suggested to post here too.

-------------------------------------------------------------------------------------

I am new to JMS and have an issue connecting to a remote JMS queue from my standalone client. Any hints on resolving this issue would be highly appreciated.

Right now I have a JavaFX standalone application that runs on multiple clients and a glassfish server 3.1.2.2 running on a remote Unix machine. I am having a hard time pushing messages from my standalone app on to the queue that is residing on the server.

-------------------------------------------------------------------------------------
Client Mc: Windows PC (No server installed)
Remote Mc: Unix (GlassFish 3.1.2.2 installed)
-------------------------------------------------------------------------------------

*JMS resources on the server:*

+JMS Destination Resource+

JNDI Name: jms/ReferralQueue
Physical Destination Name: ReferralQueue
Resource Type: javax.jms.Queue

+JMS Connection Factory+

Pool Name: jms/ReferralConnectionFactory
JNDI Name: jms/ReferralConnectionFactory
Resource Type: javax.jms.QueueConnectionFactory

JMS Service Type: Embedded
JMS Message Store Type: File

*Client Side Code to connect to the server:*

+jms.properties:+

org.omg.CORBA.ORBInitialHost=UNIX MC URL
org.omg.CORBA.ORBInitialPort=3700
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl

+Service Locator design to implement resource caching+

public class JMSServiceLocator {     private static JMSServiceLocator singletonService = null;
    private static QueueConnectionFactory qFactory;
    private static Queue queue;
    private InitialContext context;
    private static Properties properties = new Properties();
    private Map cache;     static {
        try {
            singletonService = new JMSServiceLocator();
        } catch (Exception e) {
            //error handling
        }
    }     private JMSServiceLocator() {
        try {
            loadProperties();
            context = new InitialContext(properties);
            cache = Collections.synchronizedMap(new HashMap());
        } catch (Exception e) {
            //error handling
        }
    }     public static JMSServiceLocator getInstance() {
        return singletonService;
    }     public QueueConnectionFactory getQueueConnectionFactory() {         String qConnFactoryName = "jms/ReferralConnectionFactory";
        qFactory = null;
        try {             System.out.println("/********************Comment after Testing*****************************/");
            Hashtable env = context.getEnvironment();
            System.out.println("**env.size::" + env.size());
            Enumeration names = env.keys();
            while (names.hasMoreElements()) {
                String str = (String) names.nextElement();
                System.out.println("**" + str + "=" + env.get(str));
            }
            System.out.println("/**********************************************************************/");             if (cache.containsKey(qConnFactoryName)) {
                qFactory = (QueueConnectionFactory) cache.get(qConnFactoryName);
            } else {
                qFactory = (QueueConnectionFactory) context.lookup(qConnFactoryName);
                cache.put(qConnFactoryName, qFactory);
            }
        } catch (Exception e) {
            //error handling
        }
        return qFactory;
    }     public Queue getQueue() {
        String queueName = "jms/ReferralQueue";
        queue = null;
        try {
            if (cache.containsKey(queueName)) {
                queue = (Queue) cache.get(queueName);
            } else {
                queue = (Queue) context.lookup(queueName);
                cache.put(queueName, queue);
            }
        } catch (Exception e) {
          //error handling
        }
return queue;
    }     private static void loadProperties() {
        //Load jms properties
    }
}

+Eventually sending message to the server:+

JMSServiceLocator jmsLocator = JMSServiceLocator.getInstance(); QueueConnectionFactory qConnFactory = jmsLocator.getQueueConnectionFactory();
qConnection = qConnFactory.createQueueConnection();
session = qConnection.createSession(false, ession.AUTO_ACKNOWLEDGE);
queue = jmsLocator.getQueue(); // Push and publish the message
messageProducer = session.createProducer(queue);
textMessage = session.createTextMessage();
textMessage.setText(message);
messageProducer.send(textMessage);

-------------------------------------------------------------------------------------

However using the above implementation, I am unsuccessful in achieving this. However I am able to achieve this if I have a server installed on the local system too, with 'addresslist' property defined to my local server connection factory. As I cannot install server on every client machine, this would not work in my case.

Any hints on resolving this would be highly appreciated.

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sirishvadala
Offline
Joined: 2012-04-19
Points: 0

Hmmm... Now I observe a strange behavior...

I created a new GlassFish 3.1.2.2 server instance on the client machine with no jndi, no connection factories, and no jms queues what so ever.

I have started this server instance and executed the standalone client application. Strangely, everything works fine and the message is directly being pushed to the remote queue.

Did any one come across this kind of issue? I am suspecting that probably the application is loading the dependent GlassFish jars in the classpath only when a server instance (could be any random instance, totally unrelated) is started.

I have the following jars in my standalone application classpath:

*C:\Program Files\glassfish-3.1.2.2\glassfish\lib\gf-client.jar
*C:\Program Files\glassfish-3.1.2.2\glassfish\lib\appserv-rt.jar
*C:\Program Files\glassfish-3.1.2.2\glassfish\lib\install\applications\jmsra\imqbroker.jar
*C:\Program Files\glassfish-3.1.2.2\glassfish\lib\install\applications\jmsra\imqjmsra.jar

I have spent a lot of time on this and do not want to give up at this point. Any help on this issue would be highly appreciated.

Thanks.

NOTE: Same update posted in JMS forum too