ActiveMQ - 如何处理生产者是关闭的

时间:2016-02-08 10:05:52

标签: activemq producer

以下代码创建一个使用者并注册到队列:

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);

问题在于我们偶尔会让制作人关闭'例外:

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)

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

0 个答案:

没有答案