Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] Can't use DispatchAfterCurrentBusStamp for async messages #32009

Copy link
Copy link
Closed
@brpauwels

Description

@brpauwels
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.