Я использую ActiveMQ 5.15.11 и пытаюсь получить количество ожидающих сообщений программно с помощью плагина StatisticsPlugin .
Ниже приведен код, используемый для создания и отправки сообщения на ActiveMQ.Statistics.Broker
:
public void produceMessage(String queueName, String message, boolean replyToTempQueue) throws JMSException {
// Create a connection factory.
final ActiveMQConnectionFactory connectionFactory =
new ActiveMQConnectionFactory(System.getenv("WIRE_LEVEL_ENDPOINT"));
// Pass the username and password.
connectionFactory.setUserName(System.getenv("ACTIVE_MQ_USERNAME"));
connectionFactory.setPassword(System.getenv("ACTIVE_MQ_PASSWORD"));
// Create a pooled connection factory.
final PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
pooledConnectionFactory.setConnectionFactory(connectionFactory);
pooledConnectionFactory.setMaxConnections(10);
// Establish a connection for the producer.
final Connection producerConnection = pooledConnectionFactory.createConnection();
producerConnection.start();
// Create a session.
final Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a queue named "MyQueue".
final ActiveMQQueue producerDestination = (ActiveMQQueue) producerSession.createQueue(queueName);
// Create a producer from the session to the queue.
final MessageProducer producer = producerSession.createProducer(producerDestination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message.
Message producerMessage = null;
// Add a reply to queue if one has been provided.
if (replyToTempQueue) {
producerMessage = producerSession.createMapMessage();
producerMessage.setJMSReplyTo(producerSession.createTemporaryQueue());
} else {
producerMessage = producerSession.createTextMessage(message);
}
// Send the message.
producer.send(producerMessage);
System.out.println("Message sent.");
producer.close();
producerSession.close();
producerConnection.close();
}
Однако, он всегда показывает размер 0. Почему это так?
ActiveMQMapMessage {commandId = 6, responseRequired = false, messageId = ID:DESKTOP-CQNTDSL-64043-1583929718154-177:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:DESKTOP-CQNTDSL-64043-1583929718154-177:1:1:1, destination = queue://ActiveMQ.Statistics.Broker, transactionId = null, expiration = 0, timestamp = 1583946785436, arrival = 0, brokerInTime = 1583946785552, brokerOutTime = 1583946785811, correlationId = null, replyTo = temp-queue://ID:DESKTOP-CQNTDSL-64043-1583929718154-177:1:1, persistent = false, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false} ActiveMQMapMessage{ theTable = {} }