我有一个Java应用程序,其中一个Quartz任务每300
毫秒运行一次,并尝试从ActiveMQ Queue中检索许多消息,假设5
并处理它们,每个请求的{{1} }分钟以释放Quartz Scheduler worker
1
protected List<?> receive(int bulkSize, String queueName, long receiveTimeoutMillis) {
LinkedList messages = new LinkedList();
try {
QueueReceiver receiver = (QueueReceiver)this.receivers.get(queueName);
if (receiver != null) {
ObjectMessage message = null;
int index = 1;
do {
message = (ObjectMessage)receiver.receive(receiveTimeoutMillis);
if (message != null) {
messages.add(message.getObject());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Message received from: " + receiver.getQueue().getQueueName() + " jms message id:" + message.getJMSMessageID());
}
message.acknowledge();
}
if (message == null) {
break;
}
++index;
} while(index <= bulkSize);
LOGGER.info("Consumed " + (index - 1) + " messages from " + queueName + ", elapsed time: " + stopWatch.getTime() + " ms");
} else {
LOGGER.warn("Queue not found " + queueName);
}
} catch (Exception var10) {
LOGGER.warn("error in performing receive: " + var10.getMessage(), var10);
}
return messages;
}
总是receiveTimeoutMillis
毫秒,150
就是bulkSize
。
当我启动我的应用程序时,每个线程使用此方法都会获得大量5
消息,但是几分钟后,尽管队列是完整并显示消息
我不知道为什么会这样!所以请给我任何提示来检查它!
即使我从队列中增加了5
方法的0
,接收者仍然没有收到任何消息!
在日志中,我从运行上述代码的每个线程中看到以下消息:
2
我正在添加每timeout
毫秒运行一次的守护程序线程
receive
和JMS类:
2019-01-29 14:59:23,893 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-2] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:24,329 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-2] Consumed 1 messages from TRANSLATOR, elapsed time: 282 ms
2019-01-29 14:59:24,500 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:24,793 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:25,097 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-18] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:25,403 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-18] Consumed 1 messages from TRANSLATOR, elapsed time: 153 ms
2019-01-29 14:59:25,693 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:25,996 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:26,300 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:26,595 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:26,898 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:27,193 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
2019-01-29 14:59:27,496 INFO com.peer39.commons.pattern.jms.JMSService - [DefaultQuartzScheduler_Worker-15] Consumed 0 messages from TRANSLATOR, elapsed time: 150 ms
最后,上面提到了接收方法。
谢谢!