I have one event with two listeners. I need to stop listener propagation when the first listener fails. For example:
Event: RegisterUserEvent Listeners: StoreUserListener and SendVerificationEmailListener
If, for any reason, the user can't be stored in database, I want that SendVerificationEmailListener doesn't execute.
I'm I using Lumen 8.x and the events are processed with Redis.
Part of my code is (Registering Events and Listeners):
`protected $listen = [
RegisterReservationEvent::class => [
RegisterReservationInDatabase::class,
SendReservationEmail::class
],
];`
First listener executed:
`public function handle(RegisterReservationEvent $event): bool
{
try {
if (formReservationExists($event->formId, $event->guestReservationId)) {
throw new FormException("Reservation {$event->guestReservationId} already registered in form {$event->formId}");
}
$data = [
'form_id' => $event->formId,
'guest_reservation_id' => $event->guestReservationId,
'token' => Str::uuid()->toString(),
'status' => 'ready_to_send',
];
$reservation = FormReservation::create($data);
if ($reservation === null) {
throw new FormException("Error saving reservation {$event->guestReservationId} in form {$event->formId}");
}
} catch (Exception $e) {
dump($e->getMessage());
return false;
}
}`
And the listener that I don't want to execute is:
`public function handle(RegisterReservationEvent $event)
{
dump('Executed for ' . $event->guestReservationId);
}`
But it was executed anyway..
I am using Redis to process the listeners.
And this is the result when queue runs
Thanks.