Skip to content

Use SymfonyMessenger instead of SimpleBus #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Atala opened this issue Mar 17, 2025 · 0 comments · May be fixed by coopcycle/coopcycle-web#4962
Open

Use SymfonyMessenger instead of SimpleBus #281

Atala opened this issue Mar 17, 2025 · 0 comments · May be fixed by coopcycle/coopcycle-web#4962
Assignees
Labels
enhancement New feature or request tech debt

Comments

@Atala
Copy link
Member

Atala commented Mar 17, 2025

SimpleBus support was dropped ~2 years ago in favor of SymfonyMessenger

See: SimpleBus/SimpleBus#37

How is it working now?

  • we use CommandBusBundle to implement the "event" pattern
  • in these commands we can record Events that will be handled after the Command has run. all of these events are handled synchronously.
  • the Domain/Middleware/EventStoreMiddleware.php is registering all events in the DB as OrderEvent and TaskEvent , so we must reimplement it

How to migrate?

In symfony messenger everything is messages ( As far as Messenger is concerned, commands and events all look identical. The difference comes down to each supporting a different design pattern. ref )
So we have just to replace simplebus commands and simplebus events by symfony messenger messages.
We can now use the attribute AsMessageHandler to register the handler automatically
!! if we want to have the same behaviour as before, that the events are handled after the command is succesfull, we must use DispatchAfterCurrentBusMiddleware Middleware

Buses

for now we have only one bus, the default bus. we could add a new bus command_bus to replace SimpleBus command, so it would be clearer (and set event_bus as default bus). See doc here

maybe we could even have order_bus and task_bus so it corresponds to what we had before

Registering TaskEvent and OrderEvent

We need to register a custom middleware in order to register these entities : https://symfony.com/doc/5.x/messenger.html#middleware

The middleware are executed when the message is dispatched but also again when a message is received via the worker (for messages that were sent to a transport to be handled asynchronously). Keep this in mind if you create your own middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tech debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant