1
votes

I am using the Laravel package https://github.com/bschmitt/laravel-amqp/ to publish and consume the message using RabbitMQ in a Microservices based application. I am publishing the message in service and trying to consume the same in another service.

The documentation is pretty clear on the code to consume the published message in the queue. However, in the traditional Laravel queue process, we would describe the process to be performed inside the handle() method. And call the php artisan queue:work command to execute the queue.

But here in the documentation, the code is clear to consume the message but How to consume the message and execute the same with an artisan command is confusing.

where would I write the code below code in Laravel application and listen to it in production server:

Amqp::consume('queue-name', function ($message, $resolver) {

var_dump($message->body);

$resolver->acknowledge($message);

});

For now, am consuming the message from the queue in the AppServiceProvider.php file boot() method. But not sure whether it is the correct way to follow.

1

1 Answers

1
votes

The way to consume messages is to create a custom artisan command to listen to the queue. We need to run the command and handle the keep alive ourselves as the package does not provide any boilerplate for the same. The connection can be kept alive by making the param Persistent to true in the configuration.