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

Rob Harrop rob at rabbitmq.com
Fri Oct 15 06:50:11 BST 2010


I think the issue here is that you have noAck=true and you're calling basicAck. There was a mistake in my initial reply and I'm not sure if you saw my follow up.

You need to call basicGet with noAck=false if you're using basicAck.

Rob





On 15 Oct 2010, at 05:24, sam_mis <sameek at arosys.com> wrote:

> 
> 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.
> 
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list