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

时间:2010-01-13 08:46:21

标签: java jboss jms jndi

我想创建java客户端项目以使用JNP Protocal连接到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

1 个答案:

答案 0 :(得分:0)

另外:

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