8000 [Messenger] Can't use DispatchAfterCurrentBusStamp for async messages · Issue #32009 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Messenger] Can't use DispatchAfterCurrentBusStamp for async messages #32009
Closed
@brpauwels

Description

@brpauwels

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0