I have two Laravel projects running on the same server.
The first calls second’s api over HTTP, the the second pushes a job to notify some users.
As both projects live on the same server, can’t i make the first project push the job to the second one’s redis job queue?
2
Answers
I never tried this approach but it should be possible
You didn’t specify what queue connections are your projects using, but let’s assume that they use 2 different connections, for example 2 different redis servers
In your first laravel project
config/queue.php
add new connection toconnections
that will point to the queue connection of the second laravel project. Let’s name itproject-2-connection
Then you can use dispatching to a particular connection
It’s important to make sure that the same job class
ExampleJob
exists in both projectsTo make your life easier you should pass
$data
as simple array and avoidSerializesModels
. If you pass model from project 1 that doesn’t exist in project 2 then your job will will fail with aModelNotFoundException
. You could use models but then you would need to have same model in both projectsSet-up a queue management server and this can receive of point your jobs into queues from even multiple servers. A simple code which might help is below;