我编写了一个异步进程来从 IBM MQ 队列订阅消息,但找不到任何方法来了解队列的大小
Queue queue;
QueueSession session;
QueueReceiver receiver;
QueueConnection con;
con=factory.createQueueConnection("user1"," password1");
queue= new MQQueue("myQueue");
session=con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
receiver=session.createReceiver(queue);
receiver.setMessageListener(this);
con.start();
上面是我正在使用的功能,在此接收器属性中没有显示任何大小或长度方法来检查那里的消息数量
公共 int countMessages() {
return jmsTemplate.execute(session -> {
Queue queue = session.createQueue(failedQueue);
QueueBrowser browser = session.createBrowser(queue);
Enumeration<?> messages = browser.getEnumeration();
int count = 0;
while (messages.hasMoreElements()) {
messages.nextElement();
count++;
}
if (count > thresholdFailedMQ) {
verifyAndRePushFailedMessages();
}
browser.close();
return count;
}, true); // true to allow for transaction
}
}