'Processing events in Lumen from another Laravel project on same DB
I'm working on a Laravel 8 project, and have a Laravel Lumen 8 project sitting along side my Laravel project. Both connect to the same database, and the database has the jobs and failed_jobs table.
Ideally, I want to simply dispatch an Event from my Laravel project and have my smaller, microservice Laravel Lumen project listen for this event in some way and process it and save something back to my database.
I've generated an Event called RedirectWatcher in my Laravel project and need a LogRedirect listener in my Lumen project to process this and save an entry to the DB.
My issue is that I have to register both the event and listener in both projects, like:
protected $listen = [
'App\Events\ExampleEvent' => [
'App\Listeners\ExampleListener',
],
];
And the event wouldn't exist in the Lumen project.
What's the best way to handle this without duping code?
Solution 1:[1]
An event class is simply a data container which holds the information related to the event, and the listener is where you handle business logic.
So I think best approach is to register en Event without listener in Laravel application and create a job (not listener) in Lumen application.So LogRedirect will be a job not a listener.
Make sure your event implements Illuminate\Contracts\Broadcasting\ShouldBroadcast interface.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
