-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected: 4.3.1
Description
When trying to consume a message with a DispatchAfterCurrentBusStamp, you always get the following exception:
[LogicException]
You can only use a "Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp" stamp in the context of a message handler.
How to reproduce
Like described in https://symfony.com/doc/current/messenger/message-recorder.html, I dispatch an event from inside a handler with the DispatchAfterCurrentBusStamp stamp:
$this->eventBus->dispatch(
(new Envelope($event))
->with(new DispatchAfterCurrentBusStamp())
);
The event is configured to goto an async transport. When there are no exceptions, the event is pushed to the queue as expected.
Now when I try to consume the event
bin/console messenger:consume async
The DispatchAfterCurrentBusMiddleware will always throw the following exception
[LogicException]
You can only use a "Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp" stamp in the context of a message handler.
This is because the message is now dispatched to the bus from the Worker instead of my handler. This will cause isRootDispatchCallRunning to be false inside DispatchAfterCurrentBusMiddleware.
Possible Solution
Should the DispatchAfterCurrentBusStamp be stripped from the envelope when sending a message in the SendMessageMiddleware?