fhteam/laravel-amqp

Message Acknowledgment

milsanore opened this issue · 5 comments

Hi,

Firstly thanks for developing this library, it's working well.

I'm using RabbitMQ in my project and in order to improve reliability I want to explicitly send message acknowledgments back to the RabbitMQ server. The RabbitMQ queue tutorial (https://www.rabbitmq.com/tutorials/tutorial-two-php.html) has a nice explanation of how to enable ACKs:

turn them on by setting the fourth parameter to basic_consume to false (true means no ack) and send a proper acknowledgment from the worker, once we're done with a task.

$callback = function($msg){
  echo " [x] Received ", $msg->body, "\n";
  sleep(substr_count($msg->body, '.'));
  echo " [x] Done", "\n";
  $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
};

$channel->basic_consume('task_queue', '', false, false, false, false, $callback);

Is it possible to require ACKs?
Thanks

It will require ack by default

I guess this is a Laravel question, but will Laravel implicitly ack unless there is an exception?
Thanks

Basically ack() is called in \Forumhouse\LaravelAmqp\Jobs\AMQPJob::delete which you can call when job processing is complete.

delete will be called automatically by Laravel if your job is not failed or you called release() to move it back to queue

Thanks, I figured it out:

I had artisan queue:work --tries=3 set. My message was failing, however I didn't have a failed_jobs table in my database. After Laravel fails to process the message 3 times, it dequeues the message and tries to put it in the database whether the table exists or not. So the message is removed from the queue (I guess to avoid an infinite loop) intentionally, even if it failed. So nothing to do with ack().

Thanks again.