[rabbitmq-discuss] another approach to retrieve message from queue?

sam_mis sameek at arosys.com
Fri Oct 15 05:24:23 BST 2010


Thanks for reply.i tried that code code but it read queue only once time when
another message come it's not show next message it only show old message
repeatedly.please guide me where i am doing mistake.
http://old.nabble.com/file/p29968590/Result.java Result.java 


Rob Harrop-5 wrote:
> 
> Using Channel.basicConsume along with QueueingConsumer (or another
> implementation of Consumer) is what I would recommend.
> 
> If you want to just grab a message of the queue as a one-shot action then
> you can use Channel.basicGet:
> 
> GetResponse r = channel.basicGet("thequeue", true); // note use of noAck =
> true
> 
> if(r != null) {
>  // got a message
>  byte[] contents = r.getBody();
>  doSomethingWithBody(r);
> }
> 
> Note the null check - this is important. Channel.basicGet does not block
> until a message becomes available, instead it just returns null if there
> is no message.
> 
> Hope this helps,
> 
> Rob
> 
> On 14 Oct 2010, at 07:35, sam_mis wrote:
> 
>> 
>> Hi
>> 
>> i am using the following code to read an queue and extract the messages
>> from
>> queue. I want to know that there is another approach to retrieve message
>> from queue? if there is another approach please describe the details
>> information to get the messages from queue. 
>> 
>> while (runInfinite)
>> {
>>     QueueingConsumer.Delivery delivery;
>>            try
>>            {
>>              delivery = consumer.nextDelivery();
>>            } catch (InterruptedException ie)
>>            {
>>               continue;
>>            }
>>         System.out.println("Message received-"
>> + new String(delivery.getBody()));
>> 
>> file included that contain the  code for reading and extracting message:
>> --------------------------------------------------------------------------
>> http://old.nabble.com/file/p29959643/Result.java Result.java 
>> 
>> Thanks
>> 
>> -- 
>> View this message in context:
>> http://old.nabble.com/another-approach-to-retrieve-message-from-queue--tp29959643p29959643.html
>> Sent from the RabbitMQ mailing list archive at Nabble.com.
>> 
>> _______________________________________________
>> rabbitmq-discuss mailing list
>> rabbitmq-discuss at lists.rabbitmq.com
>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
> 
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
> 
> 

-- 
View this message in context: http://old.nabble.com/another-approach-to-retrieve-message-from-queue--tp29959643p29968590.html
Sent from the RabbitMQ mailing list archive at Nabble.com.



More information about the rabbitmq-discuss mailing list