Communicating Jboss 7.1.1 with standalone application
ajinkya.bambal Sep 30, 2013 8:55 AMI am using HornetQ in Jboss 7.1.1 as a service . My Servlet (which is running under the same jboss 7.1.1 AS ) is posting message on the queue .
I want to connect and receive the message from my standalone java application for that I wrote following receiver code which implements onMessage(),
import javax.jms.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.jms.MessageListener;
import javax.naming.Context;
public class QueueReceiver implements MessageListener
{
InitialContext ic = null;
javax.jms.ConnectionFactory cf = null;
javax.jms.Connection connection = null;
javax.jms.Queue queue = null;
javax.jms.Session session = null;
Destination destination = null;
public static void main(final String[] args)
{
QueueReceiver treceiver1 = new QueueReceiver();
try
{
treceiver1.getInitialContext();
treceiver1.connectAndCreateSession();
treceiver1.consume();
treceiver1.closeConnection();
}
catch (NamingException e)
{
e.printStackTrace();
}
catch (JMSException e)
{
e.printStackTrace();
}
}
void getInitialContext() throws NamingException
{
java.util.Properties env = new java.util.Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "guest");
env.put(Context.SECURITY_CREDENTIALS, "guest");
ic= new InitialContext(env);
}
void connectAndCreateSession() throws NamingException, JMSException
{
ConnectionFactory cf = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory");
destination = (Destination) ic.lookup("jms/queue/test");
connection = cf.createConnection();
session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
connection.start();
}
public void closeConnection()
{
if (session != null)
{
try
{
session.close();
} catch (JMSException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
} catch (JMSException e)
{
e.printStackTrace();
}
}
}
public void consume()
{
try
{
MessageConsumer tconsumer = session.createConsumer(destination);
QueueReceiver trecieve = new QueueReceiver();
tconsumer.setMessageListener(trecieve);
System.out.println("Waiting for the message...");
}
catch (JMSException e)
{
e.printStackTrace();
}
}
@Override
public void onMessage(Message msg)
{
try
{
String msgText;
if (msg instanceof TextMessage)
{
msgText = ((TextMessage) msg).getText();
System.out.println("Message Received: " + msgText);
}
else
{
// If it is not a TextMessage...
msgText = msg.toString();
}
}
catch (JMSException jmse)
{
jmse.printStackTrace();
}
}
}
I have added jboss-client.jar with same version of jboss 7.1.1 AS in the application classpath ,
I have cross checked the version for both the jar files Still Exception is coming as,
javax.naming.NamingException: Failed to create remoting connection [Root exception is java.util.ServiceConfigurationError: org.xnio.XnioProvider: Provider org.xnio.nio.NioXnioProvider could not be instantiated: java.lang.NoSuchMethodError: org.jboss.logging.Logger.tracef(Ljava/lang/String;Ljava/lang/Object;)V]
at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at QueueReceiver.getInitialContext(Unknown Source)
at QueueReceiver.main(Unknown Source)
Caused by: java.util.ServiceConfigurationError: org.xnio.XnioProvider: Provider org.xnio.nio.NioXnioProvider could not be instantiated: java.lang.NoSuchMethodError: org.jboss.logging.Logger.tracef(Ljava/lang/String;Ljava/lang/Object;)V
at java.util.ServiceLoader.fail(ServiceLoader.java:207)
at java.util.ServiceLoader.access$100(ServiceLoader.java:164)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353)
at java.util.ServiceLoader$1.next(ServiceLoader.java:421)
at org.xnio.Xnio.doGetInstance(Xnio.java:187)
at org.xnio.Xnio.getInstance(Xnio.java:146)
at org.jboss.remoting3.Remoting.createEndpoint(Remoting.java:73)
at org.jboss.naming.remote.client.EndpointCache.get(EndpointCache.java:44)
at org.jboss.naming.remote.client.InitialContextFactory.createEndpoint(InitialContextFactory.java:193)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateEndpoint(InitialContextFactory.java:174)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:138)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
... 6 more
Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.tracef(Ljava/lang/String;Ljava/lang/Object;)V
at org.xnio.nio.NioXnio.<init>(NioXnio.java:76)
at org.xnio.nio.NioXnioProvider.<clinit>(NioXnioProvider.java:34)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:345)
... 15 more
Please help me out I am stuck.