5150studios's avatar

RabbitMQ Between 2+ Laravel Services

Hey guys,

Really stuck on a problem with trying to have long listening workers in Laravel.

Error I can push messages onto RabbitMQ and see them being queued up in the RabbitMQ Dashboard, I can even push up a test using the "Fanout" method with 2 simple PHP scripts but I simply don't know where to begin on the Laravel end for listening to these queues.

Goal

  1. Push a message onto RabbitMQ from Laravel (Service 1)
  2. 1 or more additional Laravel Services are looking for that event, say UserUpdated and can grab it's message, perform their tasks and finish

Help How do you get a long lived queue or job running in Laravel listening for events pushed to RabbitMQ? I've gone through so many packages now on GitHub and none of them explain this clearly. Your help is much appreciated.

Example Scripts for Pub/Sub https://blog.programster.org/rabbitmq-exchanges-with-php

0 likes
3 replies
shez1983's avatar

you will probably need to create a console command - that continually listens to the queue.. and then do whatever you need to do - or am i over simplifying / not getting what you want.. :s

you will probably have to figure out the code on how to 'connect to rabbitMQ and get the jobs off the queue in laravel ' unless there is a package - if no package then look at the api/underlying method and build a simple functionality yourself

jjudge's avatar

If you are pushing and listening for Laravel jobs on the RabbitMQ queue, then this package seems to be the most common one to do that for you (TBH, probably the only package to do this):

https://github.com/vyuldashev/laravel-queue-rabbitmq

If you are pushing and subscribing to plain JSON payloads, perhaps sending messages between applications that may not even be Laravel, then there are a number of packages that provide bridges to do this in Laravel:

Documentation quality and completeness varies wildly, and most packages don't even say up front what they are giving you. You also must know how to set up RabbitMQ, as all the packages assume you have a plan for that.

Please or to participate in this conversation.