Skip to content

[Messenger][WIP] Show how to configure multiple buses #10016

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions messenger/multiple-buses.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. index::
single: Messenger; Multiple buses

Multiple Buses
==============

A common architecture when building application is to separate commands from
queries. Commands are actions that do something and queries fetches data. This
is called CQRS (Command Query Responsibility Segregation). See Martin Fowler's
`article about CQRS`_ to learn more. This architecture could be used together
with the messenger component by defining multiple buses.

A **command bus** is a little different form a **query bus**. As example,
command buses must not return anything and query buses are rarely asynchronous.
You can configure these buses and their rules by using middlewares.

It might also be a good idea to separate actions from reactions by introducing
an **event bus**. The event bus could have zero or more subscribers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're mentioning that events have zero or more subscribers, we should probably mention that commands and queries have exactly one handler.


.. configuration-block::

.. code-block:: yaml

framework:
messenger:
default_bus: messenger.bus.command
buses:
messenger.bus.command:
middleware:
- messenger.middleware.validation
- messenger.middleware.handles_recorded_messages: ['@messenger.bus.event']
- doctrine_transaction_middleware: ['default']
messenger.bus.query:
middleware:
- messenger.middleware.validation
messenger.bus.event:
middleware:
- messenger.middleware.allow_no_handler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 4.2, default_middleware: allow_no_handlers must be used instead.

(https://github.com/symfony/symfony/blob/master/UPGRADE-4.2.md#frameworkbundle)

- messenger.middleware.validation

.. _article about CQRS: https://martinfowler.com/bliki/CQRS.html