如何使用Java通过JNP协议连接JBossMQ服务器?
我想创建java客户端项目来使用JNP协议连接到JBossMQ服务器。 但它有错误“org.jboss.jms.exception.MessagingNetworkFailureException “当它开始创建连接时。
你能帮我提供任何建议或指导我找到任何资源吗?我认为它有一些我遗漏的点,但我无法识别。
我的代码:
package examplejboss;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.*;
import javax.naming.*;
/**
*
* @author HuHOo
*/
public class Producer {
/**
* simple Producer
*/
public Producer() throws NamingException {
try {
Hashtable env;
Context ctx = null;
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
try {
// Create the initial context.
ctx = new InitialContext(env);
} catch (NamingException ex) {
ex.printStackTrace();
System.exit(-1);
}
ConnectionFactory cf = (javax.jms.ConnectionFactory) ctx.lookup("ConnectionFactory");
Connection connection = cf.createConnection();
Session session = connection.createSession(false /* not transacted */, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)ctx.lookup("queue/A");
MessageProducer producer = session.createProducer(queue);
TextMessage outMsg = session.createTextMessage("40");
System.out.println("Sending message: " + outMsg.getText());
producer.send(outMsg);
// now that everything is ready to go, start the connection
connection.start();
producer.close();
session.close();
connection.close();
} catch (JMSException ex) {
System.out.println("Error running program");
ex.printStackTrace();
}
}
/**
* main method
*/
public static void main(String args[]) {
try {
new Producer();
} catch (NamingException ex) {
Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
error :
log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.
Error running program
org.jboss.jms.exception.MessagingNetworkFailureException
at org.jboss.jms.client.delegate.DelegateSupport.handleThrowable(DelegateSupport.java:245)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientConnectionFactoryDelegate$createConnectionDelegate$aop(ClientConnectionFactoryDelegate.java:187)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.java)
at org.jboss.jms.client.container.StateCreationAspect.handleCreateConnectionDelegate(StateCreationAspect.java:83)
at org.jboss.aop.advice.org.jboss.jms.client.container.StateCreationAspect_z_handleCreateConnectionDelegate_27553328.invoke(StateCreationAspect_z_handleCreateConnectionDelegate_27553328.java)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.java)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.createConnectionDelegate(ClientConnectionFactoryDelegate.java)
at org.jboss.jms.client.JBossConnectionFactory.createConnectionInternal(JBossConnectionFactory.java:205)
at org.jboss.jms.client.JBossConnectionFactory.createConnection(JBossConnectionFactory.java:87)
at org.jboss.jms.client.JBossConnectionFactory.createConnection(JBossConnectionFactory.java:82)
at examplejboss.Producer.<init>(Producer.java:42)
at examplejboss.Producer.main(Producer.java:78)
Caused by: org.jboss.remoting.ConnectionFailedException: Timed out trying to create control socket
at org.jboss.remoting.transport.bisocket.BisocketClientInvoker.handleConnect(BisocketClientInvoker.java:273)
at org.jboss.remoting.MicroRemoteClientInvoker.connect(MicroRemoteClientInvoker.java:294)
at org.jboss.remoting.Client.connect(Client.java:1596)
at org.jboss.remoting.Client.connect(Client.java:498)
at org.jboss.remoting.callback.ServerInvokerCallbackHandler.connect(ServerInvokerCallbackHandler.java:166)
at org.jboss.remoting.ServerInvoker.getCallbackHandler(ServerInvoker.java:2047)
at org.jboss.remoting.ServerInvoker.handleInternalInvocation(ServerInvoker.java:1663)
at org.jboss.remoting.transport.bisocket.BisocketServerInvoker.handleInternalInvocation(BisocketServerInvoker.java:863)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:895)
at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:549)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
at org.jboss.remoting.Client.invoke(Client.java:1544)
at org.jboss.remoting.Client.addCallbackListener(Client.java:1613)
at org.jboss.remoting.Client.addListener(Client.java:907)
at org.jboss.jms.client.remoting.JMSRemotingConnection.addInvokerCallbackHandler(JMSRemotingConnection.java:230)
at org.jboss.jms.client.remoting.JMSRemotingConnection.start(JMSRemotingConnection.java:340)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientConnectionFactoryDelegate$createConnectionDelegate$aop(ClientConnectionFactoryDelegate.java:154)
... 10 more
I would like to create java client project to connect to JBossMQ server by use JNP Protocal.
but It have error "org.jboss.jms.exception.MessagingNetworkFailureException
" when it start to create connection.
Could you help me by give any suggestion or guide me to any resource? I think it has some point I'm missing but I can't recognize.
My code :
package examplejboss;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.*;
import javax.naming.*;
/**
*
* @author HuHOo
*/
public class Producer {
/**
* simple Producer
*/
public Producer() throws NamingException {
try {
Hashtable env;
Context ctx = null;
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
try {
// Create the initial context.
ctx = new InitialContext(env);
} catch (NamingException ex) {
ex.printStackTrace();
System.exit(-1);
}
ConnectionFactory cf = (javax.jms.ConnectionFactory) ctx.lookup("ConnectionFactory");
Connection connection = cf.createConnection();
Session session = connection.createSession(false /* not transacted */, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)ctx.lookup("queue/A");
MessageProducer producer = session.createProducer(queue);
TextMessage outMsg = session.createTextMessage("40");
System.out.println("Sending message: " + outMsg.getText());
producer.send(outMsg);
// now that everything is ready to go, start the connection
connection.start();
producer.close();
session.close();
connection.close();
} catch (JMSException ex) {
System.out.println("Error running program");
ex.printStackTrace();
}
}
/**
* main method
*/
public static void main(String args[]) {
try {
new Producer();
} catch (NamingException ex) {
Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
error :
log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.
Error running program
org.jboss.jms.exception.MessagingNetworkFailureException
at org.jboss.jms.client.delegate.DelegateSupport.handleThrowable(DelegateSupport.java:245)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientConnectionFactoryDelegate$createConnectionDelegate$aop(ClientConnectionFactoryDelegate.java:187)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.java)
at org.jboss.jms.client.container.StateCreationAspect.handleCreateConnectionDelegate(StateCreationAspect.java:83)
at org.jboss.aop.advice.org.jboss.jms.client.container.StateCreationAspect_z_handleCreateConnectionDelegate_27553328.invoke(StateCreationAspect_z_handleCreateConnectionDelegate_27553328.java)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_N3019492359065420858.java)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.createConnectionDelegate(ClientConnectionFactoryDelegate.java)
at org.jboss.jms.client.JBossConnectionFactory.createConnectionInternal(JBossConnectionFactory.java:205)
at org.jboss.jms.client.JBossConnectionFactory.createConnection(JBossConnectionFactory.java:87)
at org.jboss.jms.client.JBossConnectionFactory.createConnection(JBossConnectionFactory.java:82)
at examplejboss.Producer.<init>(Producer.java:42)
at examplejboss.Producer.main(Producer.java:78)
Caused by: org.jboss.remoting.ConnectionFailedException: Timed out trying to create control socket
at org.jboss.remoting.transport.bisocket.BisocketClientInvoker.handleConnect(BisocketClientInvoker.java:273)
at org.jboss.remoting.MicroRemoteClientInvoker.connect(MicroRemoteClientInvoker.java:294)
at org.jboss.remoting.Client.connect(Client.java:1596)
at org.jboss.remoting.Client.connect(Client.java:498)
at org.jboss.remoting.callback.ServerInvokerCallbackHandler.connect(ServerInvokerCallbackHandler.java:166)
at org.jboss.remoting.ServerInvoker.getCallbackHandler(ServerInvoker.java:2047)
at org.jboss.remoting.ServerInvoker.handleInternalInvocation(ServerInvoker.java:1663)
at org.jboss.remoting.transport.bisocket.BisocketServerInvoker.handleInternalInvocation(BisocketServerInvoker.java:863)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:895)
at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:549)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
at org.jboss.remoting.Client.invoke(Client.java:1544)
at org.jboss.remoting.Client.addCallbackListener(Client.java:1613)
at org.jboss.remoting.Client.addListener(Client.java:907)
at org.jboss.jms.client.remoting.JMSRemotingConnection.addInvokerCallbackHandler(JMSRemotingConnection.java:230)
at org.jboss.jms.client.remoting.JMSRemotingConnection.start(JMSRemotingConnection.java:340)
at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientConnectionFactoryDelegate$createConnectionDelegate$aop(ClientConnectionFactoryDelegate.java:154)
... 10 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另外:
服务器有日志:收到了无法识别的listenerId的新控制套接字
addition :
Server have log : received new control socket for unrecognized listenerId