I am using spring-rabbitmq ,and I can get messages successfully. but when I debug I found that the listener creates a thread and it will ask for messages every 1 second .I think the rate is too high .what I want to do is to set the rate 1 min or any other. I search a lot but does not works
My springrabbit.xml:
<rabbit:listener-container connection-factory="connectionFactory" message-converter="jsonMessageConverter" >
<rabbit:listener queues="notification" ref="messageReceiver"/>
</rabbit:listener-container>
my java code :
@Override
public void onMessage(Message message) { System.out.println("messagebody: "+new String(message.getBody()));
LOGGER.info(dateFormatUtil.getDateFormat(new Date())+new String(message.getBody()));
boolean result=false;
SendSingleEmailService sendSingleEmailService = new SendSingleEmailService();
try {
result =sendSingleEmailService.send(new String(message.getBody()));
} catch (FileNotFoundException e) {
LOGGER.error(dateFormatUtil.getDateFormat(new Date())+"[NOTIFICATION] [ERROR] message is null!");
e.printStackTrace();
}
if(!result) {
try{
throw new Exception();
}catch (FileNotFoundException e) {
throw new RuntimeException(e);
}catch (Exception e) {
throw new RuntimeException(e);
}finally {
LOGGER.error(dateFormatUtil.getDateFormat(new Date())+"[NOTIFICATION] [ERROR] Send Email failed!");
}
}
}
Some of debug results are as follows:
[2017-08-16 18:23:08,595]DEBUG 4286[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:09,600]DEBUG 5291[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:10,602]DEBUG 6293[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:11,603]DEBUG 7294[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:12,609]DEBUG 8300[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:13,612]DEBUG 9303[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:14,615]DEBUG 10306[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:15,617]DEBUG 11308[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:16,618]DEBUG 12309[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0
[2017-08-16 18:23:17,619]DEBUG 13310[SimpleAsyncTaskExecutor-1] - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:186) - Retrieving delivery for Consumer: tag=[amq.ctag-5AR22lnMjmLAj329LDpGbQ], channel=Cached Rabbit Channel: AMQChannel(amqp://admin@192.168.203.151:5672/,1), acknowledgeMode=AUTO local queue size=0