How to do to connect to remote jms queue

jbossjmsjndi

I have working JBoss AS 7 (7.1.1 final) server on localhost with some queue.

And I want to connect to that queue in a desktop application.

So I wrote something like this:

Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
InitialContext initialContext = new InitialContext(env);
ConnectionFactory connectionFactory = (ConnectionFactory) 
initialContext.lookup("RemoteConnectionFactory"); // <- there is it fail

But it results in this exception:

Exception in thread "main" javax.naming.CommunicationException: Could
not obtain connection to any of these urls: remote://localhost:4447
and discovery failed with error: javax.naming.CommunicationException:
Receive timed out [Root exception is java.net.SocketTimeoutException:
Receive timed out] [Root exception is
javax.naming.CommunicationException: Failed to connect to server
remote:1099 [Root exception is
javax.naming.ServiceUnavailableException: Failed to connect to server
remote:1099 [Root exception is java.net.UnknownHostException:
remote]]]

Of course, I have jbosscall-client.jar in class path.

Best Answer

You need to replace the remote in the PROVIDER_URL with jnp something similar to

### JBossNS properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Related Topic