【问题标题】:ActiveMQ 5.15.3 shows 0 producerCount in the web consoleActiveMQ 5.15.3 在 Web 控制台中显示 0 producerCount
【发布时间】:2018-11-28 00:39:58
【问题描述】:

activemq web 控制台中的生产者计数始终显示 0,即使有生产者连接到代理。我不确定为什么?

我的生产者代码如下所示。

public boolean postMessage(List<? extends JMSMessageBean> messageList, String data, int messageCount)
        throws JMSException {
    String queueName = null;
    MessageProducer producer = null;
    Connection connection = null;
    Session session = null;
    try {
        connection = pooledConnectionFactory.createConnection();
        connection.setExceptionListener(this);
        connection.start();
        session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

        int index = 0;
        for (JMSMessageBean message : messageList) {
            if (producer == null || !message.getQueueName().equals(queueName)) {
                queueName = message.getQueueName();
                producer = getQueueProducer(queueName, session);
            }

            Message _omessage = session.createObjectMessage(message);
            _omessage.setStringProperty("MESSAGE_INDEX", messageCount + ":" + index);
            _omessage.setIntProperty("RETRY_COUNT", 0);
            _omessage.setJMSType(message.getJmsType());
            if (data != null) {
                _omessage.setStringProperty("RAW_DATA", data);
            }
            producer.send(_omessage);
            index++;
        }

    } catch (JMSException e) {
        logger.error("Exception while creating connection to jms broker", e);

    } finally {
        try {
            if (null != session) {
                session.close();
            }
            if (null != connection) {
                connection.close();
            }
            if(null != producer) {
                producer.close();
            }
        } catch (JMSException e) {
            logger.error(e.getMessage(), e);
        }
    }

    return true;
}

我正在使用 pooledconnectionfactory 来创建会话、连接和消息生产者。每次,有人必须发布消息时,都会从 pooledconnectionfactory 请求一个新的连接。然后

【问题讨论】:

  • 如果我不使用 PooledConnectionFactory,那么我可以看到 producerCount 为正数。但我需要使用 PooledConnectionFactory API。谁能帮忙,怎么办..

标签: activemq


【解决方案1】:

ActiveMQ 客户端经常使用他们所谓的“动态生产者”——非事务会话的每个消息的生产者。如果您了解了 JMS 对象的生命周期,您会发现几乎不需要在非事务会话中保留生产者对象——这与消费者对象不同。

查看 JMX 中的 dynamicProducers 列表,您会发现它们正在被创建。您还可以监控咨询主题以查看它们的创建和销毁。

旁注:finally 中的对象关闭顺序不正确。您应该以相反的顺序关闭对象——生产者、会话、连接。

【讨论】:

    猜你喜欢
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    相关资源
    最近更新 更多