Description
Description
In relation to: https://symfony.com/doc/current/messenger/message-recorder.html
Currently, to inform the event bus we have to add a stamp to a message.
That works fine for most of the time, but in my case I have a service class that can be started in different contexts - from a message handler and from a console command.
- In the first scenario the message goes through the handler of the "command bus". Everything works fine.
- In the second scenario, event is emitted directly, yet the event bus will not accept the message, stating that "You can only .... in the context of a message handler."
I think that dispatch after current bus could be strictly tied to a bus, not a message itself.
When dispatching a message I need to be aware of the context in which the application is running, therefore it leads to more complicated code IMHO (I have to add a stamp every time I know I'm in a handler).
The other way around is to still accept messages even if "isRootDispatchCallRunning" is not true
in \Symfony\Component\Messenger\Middleware\DispatchAfterCurrentBusMiddleware:47
and the stamp is present.
Right now, we decided to detect in our own middleware whether we are in a context of some handler and then remove the stamp before passing the message to DispatchAfterCurrentBusMiddleware
.
@Nyholm, please let me know what do you think.