public class ChatClient implements MessageListener ,ExceptionListener{ @Override public void onException(JMSException exception) { System.err.println("there is a problem with the connection"); System.out.println("wait for reestablish connection"); establishConn(); } private void establishConn() { conn = JNDIUtil.crateQueueConnection(); try { conn.setExceptionListener(this); } catch (JMSException e) { e.printStackTrace(); } } } 用于诱捕丢失的连接 因为客户端只是监听,没调用相应的send publish 方法,不会感知到异常的发生,所以有了ExceptionListener