[rabbitmq-discuss] data being fetched from other queues too(that are not named in basicConsume)

Amr Mostafa amr.mostafa at gmail.com
Tue Apr 12 16:23:35 BST 2011


Hi Kamal,

First off, if you want to use the asynchronous model then you don't need to
use basicConsume with each message fetch. This is something that you do at
the initialization of application/class, then you just use nextDelivery for
fetching messages.

It appears to me that you should also use 3 consumers, one for each queue.
Assuming they are called "highConsumer", "mediumConsumer" and "lowConsumer".
Then to fetch the next available message from the "high" queue you should
call: this.highConsumer.nextDelivery(), and so on.

I hope that gives you a better idea of what's wrong in your code.

Finally, there may be a way for you to

Regards,

On Tue, Apr 12, 2011 at 8:48 AM, Kamal Nandan <kamal.nandan at impetus.co.in>wrote:

>  Hi Mustafa,
>
>
>
> Thanks for your help…
>
>
>
> Infact, I need an asynchronous version only so that my code doesn’t keep on
> polling the server for new messages..
>
>
>
> My query is, if we have done something like this:
>
>
>
> *boolean* autoAck = *false*;
>
>
>
>             System.*out*.println("fetching message from the Q: " +
> queueName + "\n");
>
>             *this*.channel.basicConsume(queueName, autoAck, *this*.queueingConsumer);
> // We are trying to fetch the data from the specified queue name *only*
>
>
>
>             QueueingConsumer.Delivery delivery;
>
>
>
>             *try* {
>
>                   delivery = *this*.queueingConsumer.nextDelivery(timeout);
> //Shouldn’t this fetch the data from the specified queue only and not some
> other queue(s); FYI, the same channel has been bound to a no. of queues; I
> hope this is not the culprit???
>
>
>
>             } *catch* (InterruptedException ie) {
>
>                   *return* *null*;
>
>             }
>
>             *if*(delivery != *null*)
>
>             {
>
>                   channel.basicAck(delivery.getEnvelope().getDeliveryTag(),
> *false*);
>
>                   *byte*[] body = delivery.getBody();
>
>                   *return* body;
>
>             }
>
>             *else*
>
>             {
>
>                   *return* *null*;
>
>             }
>
>
>
> Since, in “channel.basicConsume”, I have passed the name of the queue from
> which data has to be fetched (and not other queues too to which the channel
> is bound to), the why do we get data from other queues too when we do “*
> this*.queueingConsumer.nextDelivery(timeout);”.
>
>
>
> Initially, I had used “basicGet”, but that will be synchronous and that’s
> the reason why I decided to use “basicConsume”.
>
>
>
> Please also see my comments in *“RED”.*
>
> * *
>
> Also, you can see a trimmed down version of my code here:
>
> http://pastebin.com/zLJpUFHA
>
>
>
> * *
>
> Thanks & Regards,
>
> Kamal
>
>
>
> *From:* rabbitmq-discuss-bounces at lists.rabbitmq.com [mailto:
> rabbitmq-discuss-bounces at lists.rabbitmq.com] *On Behalf Of *Amr Mostafa
> *Sent:* Monday, April 11, 2011 7:32 PM
> *To:* Kamal
> *Cc:* rabbitmq-discuss at lists.rabbitmq.com
> *Subject:* Re: [rabbitmq-discuss] data being fetched from other queues
> too(that are not named in basicConsume)
>
>
>
> Hi Kamal,
>
> It looks like you are mistaking Channel.basicConsume for Channel.basicGet.
> The first (which you are using) is asynchronous and what it does is
> subscribe a consumer with the messaging server on a given queue. All
> incoming messages to do that queue will be directly sent by the messaging
> server to that subscribed consumer. In the QueuingConsumer implementation,
> those received messages are held in an internal queue and you fetch them
> using nextDelivery.
>
> This model is called subscription-based, another simpler approach is using
> Channel.basicGet. I advise you to check this for details:
>
> http://www.rabbitmq.com/api-guide.html
>
> On Mon, Apr 11, 2011 at 3:19 PM, Kamal <kamal.nandan at gmail.com> wrote:
>
> Hi,
>
> I am facing a strange problem while using RabbitMq.
>
> I have a consumer that creates 3 queues(just for name sake HIGH/MEDIUM/
> LOW priority queues) on the RabbitMQ server and consumes data from the
> 3 queues in this order:
> 5 messages from HIGH
> 3 messages from MEDIUM
> 2 messages from LOW.
>
> This keeps on happening in round-robin fashion.
> If there is no data available on the respective queue, the data from
> the next queue is fetched.
>
> I am using "Channel.basicConsume(queueName, ACK, QueueingConsumer)"
> and "QueueingConsumer.nextDelivery(timeout)" to fetch the data.
>
> What I see here is: I see that the data is fetched from the other
> queues too. i.e. Even though I have passed the queuename as "HIGH",
> then too i see that the data is being fetched from the queue "LOW" or
> "MEDIUM" and vice versa. I am finding this behaviour quite strange.
> Can someone plz help me out with this.
>
> Following is a snippet of my code.:
> http://pastebin.com/s03dP91z
>
> Thanks in advance..
>
> Regards,
> Kamal
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
>
>
>
> --
> Amr Mostafa
> Egypt Development Center
> Member of NTG
> Mobile: +(2012)1700502
> Office: +(202)24052355/6 - Ext.: 2005
>
> ------------------------------
>
> Are you exploring a Big Data Strategy ? Listen to this recorded webinar on
> Planning your Hadoop/ NoSQL projects for 2011 at
> www.impetus.com/featured_webinar?eventid=37
>
> Follow us on www.twitter.com/impetuscalling or visit www.impetus.com to
> know more.
>
>
> NOTE: This message may contain information that is confidential,
> proprietary, privileged or otherwise protected by law. The message is
> intended solely for the named addressee. If received in error, please
> destroy and notify the sender. Any use of this email is prohibited when
> received in error. Impetus does not represent, warrant and/or guarantee,
> that the integrity of this communication has been maintained nor that the
> communication is free of errors, virus, interception or interference.
>



-- 
Amr Mostafa
Egypt Development Center
Member of NTG
Mobile: +(2012)1700502
Office: +(202)24052355/6 - Ext.: 2005
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20110412/f7c99a6d/attachment-0001.htm>


More information about the rabbitmq-discuss mailing list