1

以下代码创建消费者并注册到队列:

PooledConnectionFactory factory = new PooledConnectionFactory(BROKER_URL);
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destQueue = new ActiveMQQueue(queue);
Producer producer = session.createProducer(destQueue);

问题是我们偶尔会收到“Producer is closed”异常:

javax.jms.IllegalStateException: The producer is closed
        at org.apache.activemq.ActiveMQMessageProducer.checkClosed(ActiveMQMessageProducer.java:196)
        at org.apache.activemq.ActiveMQMessageProducer.getDestination(ActiveMQMessageProducer.java:153)
        at org.apache.activemq.jms.pool.PooledProducer.<init>(PooledProducer.java:43)
        at org.apache.activemq.jms.pool.PooledSession.createProducer(PooledSession.java:361)

重新启动应用程序会重新建立连接,并且消息会正确排出。有没有办法检查生产者是否已关闭并刷新连接?

4

0 回答 0