Exception in thread "main" javax.naming.CommunicationException:

hi all,

i am trying to implement jbossMQ using the sample example as following.I can compile the example and i have put all the needed Jboss Jars.

package src;

import java.util.Properties;

import javax.jms.Message;

import javax.jms.Queue;

import javax.jms.QueueConnection;

import javax.jms.QueueConnectionFactory;

import javax.jms.QueueReceiver;

import javax.jms.QueueSender;

import javax.jms.QueueSession;

import javax.jms.Session;

import javax.jms.TextMessage;

import javax.naming.Context;

import javax.naming.InitialContext;

public class Client

{

public static void main(String[] args) throws Exception

{

log.info("Creating jndi context - alternatively use a jndi.properties");

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");

properties.put(Context.PROVIDER_URL, "localhost");

InitialContext ctx = new InitialContext(properties);

log.info("Looking up queue");

Queue queue = (Queue) ctx.lookup("queue/testQueue");

log.info("Looking up connection factory");

QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");

log.info("Creating connection");

QueueConnection qc = qcf.createQueueConnection();

try

{

log.info("Creating session");

QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

log.info("Creating sender");

QueueSender sender = qs.createSender(queue);

log.info("Creating message");

TextMessage message = qs.createTextMessage("hello");

log.info("Sending message");

sender.send(message);

log.info("Creating receiver");

QueueReceiver receiver = qs.createReceiver(queue);

log.info("Try to receive message, it will not work");

Message received = receiver.receiveNoWait();

if (received != null)

throw new RuntimeException("Should not get a message if the connection is not started!");

log.info("You have to start the connection before receiving messages");

qc.start();

log.info("This receive will work");

received = receiver.receiveNoWait();

log.info("Got message: " + received);

}

finally

{

qc.close();

}

}

public static class log

{

public static void info(String message)

{

System.out.println(message);

}

public static void error(String message, Throwable t)

{

System.err.println(message);

t.printStackTrace();

}

}

}

When i run the Jboss application server it works well as expected.BUt once i stop the Jboss Application server i get the following exception:-

og4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).

log4j:WARN Please initialize the log4j system properly.

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:1302)

at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1382)

at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)

at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)

at javax.naming.InitialContext.lookup(InitialContext.java:351)

at src.Client.main(Client.java:30)

Caused by: java.net.SocketTimeoutException: Receive timed out

at java.net.PlainDatagramSocketImpl.receive0(Native Method)

at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:136)

at java.net.DatagramSocket.receive(DatagramSocket.java:712)

at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1272)

... 5 more

Does that mean i need to have JBoss application server running to implement JBoss MQ JMS implementation.Is there any other way so that i can only start few services of JBoss(instead of whole app server) to make the messaging work.

please comment.

any help would be appreciated..

thanks

[4345 byte] By [miryavera] at [2007-11-26 17:18:53]
# 1

> hi all,

> i am trying to implement jbossMQ using

>...

> Does that mean i need to have JBoss application

> server running to implement JBoss MQ JMS

> implementation.Is there any other way so that i can

> only start few services of JBoss(instead of whole app

> server) to make the messaging work.

Yes you DO need to run a JNDI naming service to be able to "lookup" the objects registered with it. I am not sure, if JBoss allows starting up only JNDI service (JNP protocol listener) separately?

The code that you have written using "lookup()" API is basically a client call. It needs a server/service to respond to that call. Your lookup() code is trying to make a socket connection on "localhost" on a default JNP port (I guess 1099?) but since there is no service listening on port 1099, it throws a socket timeout exception which is wrapped into a Communication exception by higher level java code.

-BJ

Bimalesha at 2007-7-8 23:46:52 > top of Java-index,Core,Core APIs...