-1

I am using different laravel applications as microservices.

like laravel app1 (admin) and laravel app2(user).

There are some jobs need to be pushed to queue from laravel app1 and those jobs need to be processed at laravel app2 by pulling it from queue.

both app have different source code.

I am facing a problem that, jobs which need to be processed example ProcessPodcast job need to define inside laravel app2 as it is going to process inside laravel app2.

But as class ProcessPodcast is not available in laravel app1, how can I push this job to a queue(redis I am using here) from laravel app1?

ProcessPodcast::dispatch($payload);

As you can see how the jobs get pushed into queue is as above using job name ProcessPodcast. but ProcessPodcast class is not exist in laravel app1, then how Can send a job request to laravel app2?

TylerH
  • 20,799
  • 66
  • 75
  • 101
vishal-mote
  • 362
  • 2
  • 6
  • 22
  • In my opinion: Make a secure API endpoint on app2 that triggers the job dispatch (define a job on app2) and call that API endpoint with app1 (directly or through a job). Your question is opinion based and deserve to be closed – N69S Nov 17 '22 at 11:03
  • I am using microservice architecture, I want app1 should work independent of app2. If I wanted to directly pass data from app1 to app2 by creating apis, why wouldn't I go with monolythic architecture. merge two aps in one. rather than using your opinion solution for it. – vishal-mote Nov 26 '22 at 05:58
  • Linking two app with api endpoint/webhook is not making them dependent of each other. That's how micro service architecture communicate between servers. – N69S Nov 26 '22 at 11:14

1 Answers1

1

I think You can use Redis pub/sub logic.

For example :


//app1
Redis::subscribe(['handle-queue-channel'], function ($message) {
   $data = json_decode($message,true);

   dispatch(new $data['class'](...$data['parameters']))
});

//app2
Redis::publish('handle-queue-channel', json_encode([
     'class' => 'App\Workers\PodcastWorker',
     'parameters' => [...$whatYouSendWorkerConstructor]
]));
  • Thanks for the answer, Yes I thought with pub/pub option, but queue and pub/sub have some differences. I was expecting there should be option available in laravel using queue. For solution, right now I have created mock class inside app1 for pushing data into queue, and using actual same class name in app2 for processing/listening data from queue. – vishal-mote Nov 26 '22 at 06:02