WhoAre
WhoAre

Reputation: 154

AS 7.1.1 : JNDI Look up for JMS connection factroy is not working

I am trying to write a sample program for JMS using Jboss. I went through the following link for how to use Jboss for JMS

http://docs.jboss.org/jbossmessaging/docs/usermanual-2.0.0.beta1/html/using-jms.html

I am getting an exception while looking up for ConnectionFactory i.e. "iniCtx.lookup("ConnectionFactory")"

javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] 
at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1058) 
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1127) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:478) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471) 
at javax.naming.InitialContext.lookup(Unknown Source) 
at MessageProducer.main(MessageProducer.java:46) 
Caused by: java.net.SocketTimeoutException: Receive timed out 
at java.net.PlainDatagramSocketImpl.receive0(Native Method) 
at java.net.PlainDatagramSocketImpl.receive(Unknown Source) 
at java.net.DatagramSocket.receive(Unknown Source) 
at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1038) 

The reason is, Jboss Naming Service is not running(netstat -an doesn't show any result for port 1099) . I didn't configure any specific setting for Naming Service. I let it to take default port 1099.

Am I missing any configuration? Kindly help me in running the Jboss naming service.

Specification :

Jboss : AS 7.1.1 Final JRE : 1.6 OS : Windows 7

Upvotes: 1

Views: 2558

Answers (1)

Andrzej Łach
Andrzej Łach

Reputation: 427

Seems that you mixed Jboss version with manual version. AS7 does not use jnp and the jndi port is 4447.

So having following setup in standalone-full.xml

 <security-enabled>false</security-enabled>
 ...
 <jms-destinations>
      <jms-queue name="testQueue">
           <entry name="queue/test"/>
            <entry name="java:jboss/exported/jms/queue/test"/>
      </jms-queue>
  </jms-destinations>

I am able to connect with client, code as follows:

 Connection connection = null;
 InitialContext initialContext = null;
 Properties props = new Properties();
 props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
 props.put(Context.PROVIDER_URL, "remote://localhost:4447");
 props.put(Context.SECURITY_PRINCIPAL, "appuser");
 props.put(Context.SECURITY_CREDENTIALS, "password");
          
 try {
    // Step 1. Create an initial context to perform the JNDI lookup.
    initialContext = new InitialContext(props);

    // Step 2. Perfom a lookup on the queue
    Queue queue = (Queue)initialContext.lookup("jms/queue/test");

    // Step 3. Perform a lookup on the Connection Factory
    ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("jms/RemoteConnectionFactory");

    // Step 4.Create a JMS Connection
    connection = cf.createConnection();

Update 2024: for jboss eap 7.4 doc, use

jms-queue add --queue-address=myQueue --entries=[queue/myQueue jms/queue/myQueue java:jboss/exported/jms/queue/myQueue]

will add xml <jms-queue name="testQueue" entries="queue/test java:jboss/exported/jms/queue/test"/>, the effect is same as previous .doc, and jboss eap port is usually 8080.

Upvotes: 3

Related Questions