bschmitt / laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages
MIT License
268 stars 86 forks source link

How to consume the message in Laravel #75

Open priyadarshiniMuthuraman opened 4 years ago

priyadarshiniMuthuraman commented 4 years ago

Hi,

I am using this package 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);

});
stevenklar commented 4 years ago

Create a laravel artisan command and start to consume. You will of course need to run the command and handle the keep alive yourself. This library does not provide you with any boilerplate for this.

Lincolnbiancard commented 2 years ago

@stevenklar Hey, how you doing? You can show us an example, I’ve read several forums and still can’t consume a queue of an api other than a standard api. :(

HassanElZarkawy commented 2 years ago

@Lincolnbiancard +1

ni-bschmitt commented 2 years ago

First create a command as described here: https://laravel.com/docs/8.x/artisan#command-structure Then register the command as described here: https://laravel.com/docs/8.x/artisan#registering-commands

Inside the handle method of the command please put the code from above:

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

   var_dump($message->body);

   $resolver->acknowledge($message);

});