如何使用Java通过JNP协议连接JBossMQ服务器?

发布于 2024-08-17 20:26:19 字数 6229 浏览 4 评论 0原文

我想创建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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自演自醉 2024-08-24 20:26:19

另外:

服务器有日志:收到了无法识别的listenerId的新控制套接字

addition :

Server have log : received new control socket for unrecognized listenerId

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文