JNDI lookup of connection factory is throwing java.net.SocketTimeoutException: Receive timed out Exception
mahesh_jboss May 25, 2016 8:21 AMHi All,
I am new to jboss and I am trying to write a sample application with jms using jboss-as-7.1.1.Final server. Below are the steps which I have done
1. Modified the standalone-full.xml file by adding a new queue called myQueue as shown below.
<jms-queue name="myQueue"> |
<entry name="queue/myQueue"/>
<entry name="java:jboss/exported/jms/queue/myQueue"/>
</jms-queue>
2. Started the jboss server using below command
standalone.bat --server-config=standalone-full.xml
3. The server started successfully and I can see that myQueue has been deployed.
11:25:16,660 INFO [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-2) trying to deploy queue jms.queue.myQueue
11:25:16,676 INFO [org.jboss.as.messaging] (MSC service thread 1-2) JBAS011601: Bound messaging object to jndi name java:/queue/myQueue
11:25:16,679 INFO [org.jboss.as.messaging] (MSC service thread 1-2) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/queue/myQueue
11:25:16,692 INFO [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) trying to deploy queue jms.topic.testTopic
11:25:16,729 INFO [org.jboss.as.messaging] (MSC service thread 1-3) JBAS011601: Bound messaging object to jndi name java:/topic/test
11:25:16,733 INFO [org.jboss.as.messaging] (MSC service thread 1-3) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/topic/test
11:25:16,745 INFO [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-6) trying to deploy queue jms.queue.testQueue
11:25:16,756 INFO [org.jboss.as.messaging] (MSC service thread 1-6) JBAS011601: Bound messaging object to jndi name java:/queue/test
11:25:16,762 INFO [org.jboss.as.messaging] (MSC service thread 1-6) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/queue/test
11:25:16,797 INFO [org.jboss.as.messaging] (MSC service thread 1-8) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
11:25:16,800 INFO [org.jboss.as.messaging] (MSC service thread 1-8) JBAS011601: Bound messaging object to jndi name java:/RemoteConnectionFactory
11:25:16,801 INFO [org.jboss.as.deployment.connector] (MSC service thread 1-1) JBAS010406: Registered connection factory java:/JmsXA
11:25:16,802 INFO [org.jboss.as.messaging] (MSC service thread 1-5) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory
11:25:16,824 INFO [org.hornetq.ra.HornetQResourceAdapter] (MSC service thread 1-1) HornetQ resource adaptor started
11:25:16,825 INFO [org.jboss.as.connector.services.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service thread 1-1) IJ020002: Deployed: file://RaActivatorhornetq-ra
11:25:16,831 INFO [org.jboss.as.deployment.connector] (MSC service thread 1-5) JBAS010401: Bound JCA ConnectionFactory [java:/JmsXA]
11:25:16,877 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
11:25:16,878 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 7694ms - Started 170 of 249 services (78 services are passive or on-demand)
4. I created a java file JMSConsumer with below content.
public class JmsConsumer implements MessageListener{
public static void main(String[] args) throws JMSException, NamingException {
System.out.println("***************** Entering JMS consumer******************");
InitialContext context = JmsConsumer.getInitialContext();
// Context context = new InitialContext();
ConnectionFactory queueConnectionFactory = (ConnectionFactory)context.lookup("ConnectionFactory");
System.out.println("************** Connection factory initialized****************");
QueueConnection queueConnection = (QueueConnection)queueConnectionFactory.createConnection();
QueueSession queueSession = (QueueSession)queueConnection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)context.lookup("myQueue");
QueueReceiver queueReceiver = (QueueReceiver)queueSession.createReceiver(queue);
queueReceiver.setMessageListener(new JmsConsumer());
queueConnection.start();
queueConnection.stop();
queueConnection.close();
}
public static InitialContext getInitialContext() throws NamingException {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
props.setProperty("java.naming.provider.url", "jnp://localhost:9990");
InitialContext context = new InitialContext(props);
return context;
}
@Override
public void onMessage(Message message) {
try {
System.out.println("Incoming messages are "
+ ((TextMessage) message).getText());
} catch (Exception e) {
System.out.println("Exception while parsing the message");
}
}
}
5. When I run this program I am getting the below exception
Exception in thread "main" 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 com.mahesh.ptop.JmsConsumer.main(JmsConsumer.java:23)
Caused by: java.net.SocketTimeoutException: Receive timed out
at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method)
at java.net.DualStackPlainDatagramSocketImpl.receive0(Unknown Source)
at java.net.AbstractPlainDatagramSocketImpl.receive(Unknown Source)
at java.net.DatagramSocket.receive(Unknown Source)
at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1038)
... 5 more
Can anyone please help me how to resolve this?
Thanks in advance,
Mahesh