[rabbitmq-discuss] TTL on Consumers in PHP

Alvaro Videla videlalvaro at gmail.com
Wed Jun 25 15:52:46 BST 2014


Hi Sean,

As you probably know, the code in the php library is blocking, so unless an
external event comes, there's no way to escape form the while loop that's
reading from the channel. The wait method supports a timeout tho.

Regards,

Alvaro




On Wed, Jun 25, 2014 at 3:16 PM, Sean Joyce <sean.joyce at patientco.com>
wrote:

> Michael -
>
> Apologies for asking you to be pedantic, but I'm still a little hazy on
> how I would implement my desired behavior.
>
> I actually have the 'quit' functionality embedded in my callback, though I
> stripped it out for my example for simplicity. With or without though, when
> I run my consumer, my code hits the '$this->channel->wait();' line and
> doesn't exit until an external event (new message) enters the queue. My
> preference is that a Consumer itself knows when it has sat idle long enough
> to terminate itself rather than having an external process monitor it.
>
> Should this be done by subclassing AMQPChannel? Like I said, I'm still a
> little hazy.
>
> -Sean
>
>
> On Tue, Jun 24, 2014 at 11:31 PM, Michael Klishin <mklishin at gopivotal.com>
> wrote:
>
>> On 25 June 2014 at 00:43:15, Sean Joyce (sean.joyce at patientco.com) wrote:
>> > > I've been trying to figure out where to call basic_cancel in
>> > this code, but not finding the right solution. Any tips on how
>> > to refactor and get what I want?
>> >
>> > public function consume() {
>> > $callback = function($msg) {
>> > $pMsg = new ProcessorMessage();
>> > $pMsg->onMessage($msg->body);
>> >
>> $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
>> > };
>> >
>> > $this->channel->basic_qos(null, 1, null);
>> > $this->channel->basic_consume($queue_name, '', false,
>> > false, false, false, $callback);
>> >
>> > while(count($this->channel->callbacks)) {
>> > $this->channel->wait();
>> > }
>> >
>> > }
>>
>> Sean,
>>
>> Take a look at the following 2 examples:
>>
>>
>> https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_consumer_non_blocking.php
>>
>> https://github.com/videlalvaro/php-amqplib/blob/master/demo/amqp_consumer.php#L52-54
>>
>> --
>> MK
>>
>> Staff Software Engineer, Pivotal/RabbitMQ
>>
>
>
>
> --
> *Sean M. Joyce*
> Director of Product Engineering | Patientco
> sean.joyce at patientco.com
> 888.747.2455 x412
>
>
> <http://info.patientco.com/himss>
> <http://info.patientco.com/happy-providers>
>
> As a friendly reminder, never send Protected Health Information (PHI) via
> email.
>
>
>
> CONFIDENTIALITY NOTICE:  The information contained in this email message
> may be privileged, confidential, and protected from disclosure.
> Any unauthorized use, printing, copying, disclosure, dissemination of or
> reliance upon this communication by persons other than the intended
> recipient may be subject to legal restriction or sanction. If you are not
> the intended recipient, you are hereby notified that you are not authorized
> to read, print, retain, copy, or disseminate this message, any part of it,
> or any attachments.  If you think that you have received this email
> message in error, please reply to the sender and delete this email and
> any attachments and all copies thereof from your system without reading the
> content and destroy any printouts of the e-mail or attachments promptly.
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140625/c122ee5e/attachment.html>


More information about the rabbitmq-discuss mailing list