将JMS与JBoss一起使用时,通道结束通知异常即将发生

时间:2014-03-30 11:27:19

标签: java jboss jms jboss7.x hornetq

我正在使用JMS和JBoss。但每当我运行我的消费者代码时,我总是得到以下异常

[org.jboss.as.naming] (Remoting "sorabh216901" task-2) JBAS011806: Channel end notification received, closing channel Channel ID 091878ba (inbound) of Remoting connection 007ce8a6 to /192.168.2.47:53318

我的消费者类如下:

public class TopicConsumer implements MessageListener{


    public static void main(String[] args) throws NamingException, JMSException {
        Context context = TopicConsumer.getInitialContext();
        try{
        System.out.println("Entering into the main method!!!");

        TopicConnectionFactory connectionFactory = (TopicConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
        Topic topic = (Topic) context.lookup("jms/topic/test");
        TopicConnection connection = connectionFactory.createTopicConnection("testuser", "testpassword");
        TopicSession session = connection.createTopicSession(true, TopicSession.AUTO_ACKNOWLEDGE);
        session.createSubscriber(topic).setMessageListener(new TopicConsumer());
        connection.start();
        System.out.println("Exiting from the main method!!!");
        }finally{
            //context.close();
        }

    }

    public void onMessage(Message arg0) {
        System.out.println("Incoming Message : " + arg0);
    }


    public static Context getInitialContext() throws NamingException{
        Properties props = new Properties();

        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
        props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
        props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
        props.put(Context.PROVIDER_URL,"remote://192.168.2.47:4447");


        props.put("jboss.naming.client.ejb.context", true);
        // username
        props.put(Context.SECURITY_PRINCIPAL, "testuser");
        // password
        props.put(Context.SECURITY_CREDENTIALS, "testpassword");

        return new InitialContext(props);

    }
}

当我运行代码时,我在日志中获得了成功的握手,即

    INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@cd0d2e, 
receiver=Remoting connection EJB receiver [connection=Remoting connection <1e03fce>,channel=jboss.ejb,nodename=sorabh216901]} on channel Channel ID 9823d1ac (outbound) of Remoting connection 004edf4a to /192.168.2.47:4447

但程序刚关闭,在服务器日志中我收到了频道结束通知。

请建议,这里有什么问题。

1 个答案:

答案 0 :(得分:2)

TopConsumer的主要方法末尾添加以下行  类:

try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

这不会阻止JVM。并且您不会获得频道结束通知异常