CmdrSharp
CmdrSharp

Reputation: 1070

Laravel Queue Worker, RabbitMQ and running jobs generated remotely

I'll preface this by admitting slight sleep-deprivation.

The setup is as follows:

API Endpoint (Server A) receives an incoming call, and adds this to a specific queue on the RabbitMQ Server (Server B).

RabbitMQ (Server B) is simply a RabbitMQ Queue Server. Nothing more, nothing less.

Laravel Installation (Server C) is our actual Laravel install, which is meant to look for jobs on specific queues and do things with them.

We have a RabbitMQ package in the Laravel install, which allows the use of the regular Laravel Queue mechanics over a RabbitMQ connection.

The issue I've come across is that we can spawn a worker for a queue - but since we're not generating the jobs passing a $job class (the job content itself is most often a JSON array), the Laravel install has no idea what to do with the job.

So my question revolves mainly around how to approach a scenario like this. I'm thinking that using the Queue-functionality in Laravel won't do what I need it to do. Can you see an approach that I'm missing? Do I really need to spawn a daemon on a non-framework script to handle this?

Your input is much appreciated!

Upvotes: 2

Views: 6636

Answers (2)

Jason
Jason

Reputation: 4772

An alternative approach would be a listener on your Laravel application consuming the JSON messages an acting on those.

A queue listener can be created using a package such as https://github.com/bschmitt/laravel-amqp (a generic AMQP bridge for Laravel) or https://github.com/needle-project/laravel-rabbitmq (a bridge more specialised for RabbitMQ).

The queue consumer then reads the JSON payload, saves the paymload as appropriate data, then decides what jobs to dispatch as a result within the Laravel application, as handled by the https://github.com/vyuldashev/laravel-queue-rabbitmq package.

The the two applications still communicate with plain JSON, and not the Laravel-oriented JSON containing the serialised job class.

Upvotes: 2

CmdrSharp
CmdrSharp

Reputation: 1070

The solution is indeed to replicate the job code onto the one issuing the job. The code will not need every dependency that the job requires to actually function, as it only serializes the job from the one pushing it.

Upvotes: 1

Related Questions