rabbitmq AMQP::consume()

让人想犯罪 __ 提交于 2019-12-04 11:15:43

Yes, here's how:

$amqp = new AMQPConnection($your_connection_params);
$amqp->setTimeout($seconds);

Then when you call consume() on a queue, if no messages arrive within the timeout period, an AMQPException will be thrown from consume() with the message, "Resource temporarily unavailable". If you ever break out of consume() or hit a timeout, be sure to call cancel() on the queue object to properly reset the consumer. In order to do this, you need to generate a globally unique consumer tag and pass it in as an undocumented, third parameter to consume:

$tag = uniqid() . microtime(true);
$queue->consume($callback, $flags, $tag);
$queue->cancel($tag);

That way, you can call consume() again later without weird issues that will make your head spin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!