Skip to main content

connectionFactory jndi lookup from standalone client

2 replies [Last post]
Joined: 2009-04-01

Hi everyone,

I've spent more than one day trying to insert a JMS message in a queue from a standalone client.

Here is what I've done :

- from glassfish console, create a connectionFactory with JNDI name "jms/connectionFactory"
- from glassfish console, create a queue with JNDI name="jms/queue1"
- from standalone java client, create file :

java.naming.factory.initial = com.sun.jndi.fscontext.RefFSContextFactory
java.naming.provider.url = mq://localhost:7676

- from standalone java client, trying to retrieve connectionFactory :

Context initialContext = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("jms/connectionFactory");

this fails with the following error :

Exception in thread "main" javax.naming.InvalidNameException: mq://localhost:7676 [Root exception is unknown protocol: mq]

I've spent my whole day googling for answers : some say that the provider URL should point to a directory on my file system (???), so other say that the JNDI lookup should be prefixed with "cn=" : I've tried everything, but nothing has worked so far.

Any help would be appreciated :-)

Thanks !

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-04-01

Replying to myself after solving my problem even if I didn't fully understand everything I did... but maybe this can be usefull to someone else

The thing is : starting a glassfish domain ALSO starts a JMS broker, even if the documentation is not clear regarding this subject.

Step #1 : declare the connection factory ("jms/myConnectionFactory") and the queue ("jms/myQueue") from the glassfish admin console (http://localhost:4848)
Step #2 : open the Open Message Queue Administration Console ([GLASSFISH_HOME]/imq/bin/imqadmin.exe)
Step #3 : Add a new broker and connect to the existing one (on primary port : 7676)
Step #4 : create a new broker destination ("myQueue")
Step #5 : create a new object store
- java.naming.factory.initial = com.sun.jndi.fscontext.RefFSContextFactory
- java.naming.provider.url = file:///C:/tmp (use an existing directory)
Step #6 : add a new destination object (lookupName = "jms/myQueue", destinationName="myQueue")
Step #7 : add a new connection factory object (lookupName="jms/myConnectionFactory")

to send a message to a queue from a standalone java client
---------------------------------------------------------- :
java.naming.factory.initial = com.sun.jndi.fscontext.RefFSContextFactory
java.naming.provider.url = file:///C:/tmp

sample groovy code :
def initialContext = new InitialContext()
def connectionFactory = (ConnectionFactory) initialContext.lookup("jms/myConnectionFactory")
def queue = (Queue) initialContext.lookup("jms/myQueue")

to send a message to a queue from a servlet deployed in glassfish

web.xml :




sample groovy code :
def ic = new InitialContext()
def ctx = (Context) ic.lookup("java:comp/env")
def cf = (ConnectionFactory) ctx.lookup("jms/myConnectionFactory")
def queue = (Queue) ctx.lookup("jms/myQueue")

Joined: 2008-05-01

Try these settings (which work for me using GF 2.1):

This assumes GF is running on localhost - change that if not.

I am not sure of how JNDI works but I [b]think[/b] that the .url starts it off, and the type on that directs further actions. Here, iiop means uses CORBA, and it looks for the ORBInitialHost, etc. In your case, the mq isn't understood by GF so the lookup fails.