我需要帮助在Jboss-eap 6.4 HornetQ中创建远程连接
我有这段代码:
import java.util.Hashtable;
import javax.jms.*;
import javax.naming.*;
public class QueueSend {
private final static String JNDI_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
private final static String JMS_FACTORY = "jms/RemoteConnectionFactory";
private final static String QUEUE = "jms/queue/test";
private final static String jbossUrl = "remote://localhost:4447";
private static InitialContext getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, jbossUrl);
env.put(Context.SECURITY_PRINCIPAL, "appuser"); // <-- username
env.put(Context.SECURITY_CREDENTIALS, "appuser_2015"); // <-- password
return new InitialContext(env);
}
public static void main(String[] args) throws Exception {
InitialContext ic = getInitialContext();
QueueConnectionFactory qconFactory =
(QueueConnectionFactory)ic.lookup(JMS_FACTORY);
QueueConnection qcon =
qconFactory.createQueueConnection("appuser","appuser_2015");
QueueSession qsession = qcon.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)ic.lookup(QUEUE);
QueueSender qsender = qsession.createSender(queue);
qcon.start();
TextMessage msg = qsession.createTextMessage();;
msg.setText("HelloWorld");
qsender.send(msg);
qsender.close();
qsession.close();
qcon.close();
System.out.println("Message Sent!");
}
}
当我运行此代码时,它显示错误:
Exception in thread "main" javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.ExceptionInInitializerError]
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 com.wendell.QueueSend.getInitialContext(QueueSend.java:28)
at com.wendell.QueueSend.main(QueueSend.java:32)
Caused by: java.lang.ExceptionInInitializerError
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.sendVersionHeader(RemoteNamingStoreV1.java:69)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.start(RemoteNamingStoreV1.java:64)
at org.jboss.naming.remote.protocol.v1.VersionOne.getRemoteNamingStore(VersionOne.java:45)
at org.jboss.naming.remote.protocol.Versions.getRemoteNamingStore(Versions.java:49)
at org.jboss.naming.remote.client.RemoteContextFactory.createVersionedStore(RemoteContextFactory.java:68)
at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:60)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
... 6 more
Caused by: java.lang.RuntimeException: Could not find a marshaller factory for river marshalling strategy
at org.jboss.naming.remote.protocol.v1.WriteUtil.<clinit>(WriteUtil.java:50)
... 15 more
我不知道这里的问题是什么,我错过了什么吗?我哪里出错了?
请帮忙。感谢
答案 0 :(得分:0)
您可能遇到jboss-marshalling-xxxx.jar
,但错过了客户端类路径中的jboss-marshalling-river-xxxx.jar
。
将jboss-marshalling-river-xxxx.jar
jar文件添加到类路径中。
在我的情况下,我有jboss-marshalling-1.4.11.Final.jar
但在我的类路径中缺少jboss-marshalling-river-1.4.11.Final.jar
。
然后我的客户端能够对wildfly进行远程EJB调用。
我从This链接获得了一些帮助。