2014-03-30 18 views
0

我正在JBoss上使用JMS。但每當我運行我的消費者的代碼我總是得到下面的異常在使用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{[email protected], 
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 

但程序剛關閉,在服務器日誌中我收到了通道結束通知。

請提出,這裏有什麼問題。

回答

2

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

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

這不會停止JVM。你不會得到通道結束通知例外

+0

謝謝,是的,它爲我工作。 –

+0

答案是正確的,因爲它避免了程序結束,但是「通道結束通知」與該問題無關:它僅僅意味着與JNDI服務器的連接已關閉,因此它不是真正的錯誤。較新版本的JBoss(即WildFly)在調試級別記錄該消息。請參閱https://issues.jboss.org/browse/WFLY-3201和https://github.com/jbossas/jboss-remote-naming/blob/master/src/main/方法handleEnd()的源代碼的java /組織/ JBoss的/命名/遠程/協議/ V1/RemoteNamingStoreV1.java – Pino