Hello ,
I am pretty new to JMS World. I have small question I think you people will be able to answer this.
I have a JMS Server ( OpenJMS / ActiveMQ ...). QueueConnectionFactory and Queue can be registered in some JNDI Server located somewhere .. ( Assumption)
From the Stand Alone application is it possible to load the Initial context properties and get QueueConnectionFactory and Queue from JNDI?
After this I hope i will be able to send messages to this queue.
you have to create the context with the information of the server you are going to send messages to.
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");//or another class you want to use that depens on the server
env.put(Context.PROVIDER_URL, "server_IP:port");//server ip and port
Context context = new InitialContext(env);
with this context you create the connection factory
QueueConnectionFactory qcf = (QueueConnectionFactory)context.lookup("JNDI/connectionFactory");
Re: Connecting to Remote JMS Server using a Stand alone application.
Oct 26, 2005 3:45 AM
(reply 3
of 3) (In reply to
#2 )
My current code is:
env.setProperty(Context.PROVIDER_URL, "iiop://localhost:2809");
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext initCtx = new InitialContext(env);
System.out.println("Getting connection factory....");
// Finding the WAS QueueConnectionFactory
javax.jms.ConnectionFactory qcf = (javax.jms.ConnectionFactory) initCtx.lookup(JMSCF_JNDI_NAME);
System.out.println("qcf="+qcf);
// Finding the Queue Destination
Destination q = (Destination) initCtx.lookup(JMSQ_JNDI_NAME);
I am getting exception as:
Oct 26, 2005 4:10:11 PM com.ibm.ws.naming.java.javaURLContextFactory
SEVERE: javaAccessorNotSet
javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:98)
at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:73)
at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:579)
at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:528)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:275)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at sender.Main.main(Main.java:29)