3

I'm handling multiple events through an Event Subscriber instead of making separated Events/Listeners. I want to queue several of these events, but I haven't found a way to accomplish that. I've followed the official documentation, but there is no example how to choose what events I want to queue (not all the subscribers).

Any suggestions? (No individual Event/Listener, please)

1 Answer 1

18

If anyone is interested in, I've found the solution looking deeper in the Event Dispatcher.

Implementing the contract ShouldQueue on the EventSubscriber works the same than a separated Event/Listener and enqueue the events on the database. This should be documented in the official site.

Regards.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for this! I agree, it should be explicit in the docs. I'm assuming there's no way to have an Event Subscriber class contain some events which are queued and some which are not?
Thanks ! I was looking for a way to use event subscriber with queues but wasn't sure it would work as it isnt specified in the docs
i have to add, if your shouldDiscoverEvents returns true in your EventServiceProvider, then this EventSubscriber which implements ShouldQueue makes the message duplicated if you write subscribe method inside with a mapping of listened Event. So choose one. If you auto discover events, then return void and do nothing in eventSubscriber's subscribe() method. Or vice versa
When referencing an other class ([classname, methodname]): ShouldQueue should be implemented on the other class, not the subscriber. Everything else is still true today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.