[rabbitmq-discuss] 回复: How long interval fetching message from MQSERVER?

Matthias Radestock matthias at rabbitmq.com
Sun Apr 6 07:18:10 BST 2014


On 01/04/14 06:16, thomas wrote:
> pls check my code below:
>
> String message = client.getNextMessage();
> if (message != null && !message.equals("")) {
> client.sendMessage(imqRec.handler(message));
> }
>
>
> If I use while(true) loop continuously monitor RPC queue, it would be
> very resource intensive, whether you grab a message per sec or anything
> else?

You haven't told us what client library you are using. If 
client.getNextMessage() is a non-blocking operation that, say, returns 
null when there are no messages in the queue then yes, the above will be 
very resource intensive if invoked in a tight loop. Less so, obviously, 
if you insert a 1 sec delay.

Such polling is a really bad idea. Please read the RabbitMQ tutorials 
and familiarise yourself with the basic.consume AMQP operation, which 
does not require polling.

Matthias.


More information about the rabbitmq-discuss mailing list