Skip to content

Commit

Permalink
Merge branch '4.2'
Browse files Browse the repository at this point in the history
* 4.2:
  Fixed a minor syntax issue in a link
  [Messenger] Multiples buses, scoping handlers per bus, PSR-4 discovery & debug
  Added configuration for multiple buses
  • Loading branch information
javiereguiluz committed Dec 27, 2018
2 parents 6e6d126 + a4b6a8b commit bf99c17
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 109 deletions.
9 changes: 9 additions & 0 deletions components/messenger.rst
Expand Up @@ -304,5 +304,14 @@ loop, the message bus will add a :class:`Symfony\\Component\\Messenger\\Stamp\\R
stamp to the message envelopes and the :class:`Symfony\\Component\\Messenger\\Middleware\\SendMessageMiddleware`
middleware will know it should not route these messages again to a transport.

Learn more
----------
.. toctree::
:maxdepth: 1
:glob:

/messenger
/messenger/*

.. _blog posts about command buses: https://matthiasnoback.nl/tags/command%20bus/
.. _SimpleBus project: http://simplebus.io
6 changes: 3 additions & 3 deletions console/coloring.rst
Expand Up @@ -9,9 +9,9 @@ output (e.g. important messages, titles, comments, etc.).
By default, the Windows command console doesn't support output coloring. The
Console component disables output coloring for Windows systems, but if your
commands invoke other scripts which emit color sequences, they will be
wrongly displayed as raw escape characters. Install the `Cmder`_, `ConEmu`_, `ANSICON`_
,`Mintty`_ (used by default in GitBash and Cygwin) or `Hyper`_ free applications
to add coloring support to your Windows command console.
wrongly displayed as raw escape characters. Install the `Cmder`_, `ConEmu`_,
`ANSICON`_, `Mintty`_ (used by default in GitBash and Cygwin) or `Hyper`_
free applications to add coloring support to your Windows command console.

Using Color Styles
------------------
Expand Down
114 changes: 8 additions & 106 deletions messenger.rst
Expand Up @@ -423,112 +423,6 @@ your ``transports`` configuration or it can be your own receiver.
It also requires a ``--bus`` option in case you have multiple buses configured,
which is the name of the bus to which received messages should be dispatched.

Multiple Buses
--------------

If you are interested in architectures like CQRS, you might want to have multiple
buses within your application.

You can create multiple buses (in this example, a command bus and an event bus) like
this:

.. configuration-block::

.. code-block:: yaml
# config/packages/messenger.yaml
framework:
messenger:
# The bus that is going to be injected when injecting MessageBusInterface:
default_bus: messenger.bus.commands
# Create buses
buses:
messenger.bus.commands: ~
messenger.bus.events: ~
.. code-block:: xml
<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:messenger default-bus="messenger.bus.commands">
<framework:bus name="messenger.bus.commands" />
<framework:bus name="messenger.bus.events" />
</framework:messenger>
</framework:config>
</container>
.. code-block:: php
// config/packages/messenger.php
$container->loadFromExtension('framework', array(
'messenger' => array(
'default_bus' => 'messenger.bus.commands',
'buses' => array(
'messenger.bus.commands' => null,
'messenger.bus.events' => null,
),
),
));
This will generate the ``messenger.bus.commands`` and ``messenger.bus.events`` services
that you can inject in your services.

.. note::

To register a handler only for a specific bus, add a ``bus`` attribute to
the handler's service tag (``messenger.message_handler``) and use the bus
name as its value.

Type-hints and Auto-wiring
~~~~~~~~~~~~~~~~~~~~~~~~~~

Auto-wiring is a great feature that allows you to reduce the amount of configuration
required for your service container to be created. When using multiple buses, by default,
the auto-wiring will not work as it won't know which bus to inject in your own services.

In order to clarify this, you can use the DependencyInjection's binding capabilities
to clarify which bus will be injected based on the argument's name:

.. configuration-block::

.. code-block:: yaml
# config/services.yaml
services:
_defaults:
# ...
bind:
$commandBus: '@messenger.bus.commands'
$eventBus: '@messenger.bus.events'
.. code-block:: xml
<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults>
<bind key="$commandBus" type="service" id="messenger.bus.commands" />
<bind key="$commandBus" type="service" id="messenger.bus.events" />
</defaults>
</services>
</container>
Middleware
----------

Expand Down Expand Up @@ -928,4 +822,12 @@ will give you access to the following services:
#. ``messenger.sender.yours``: the sender;
#. ``messenger.receiver.yours``: the receiver.

Learn more
----------
.. toctree::
:maxdepth: 1
:glob:

/messenger/*

.. _`enqueue's transport`: https://github.com/php-enqueue/messenger-adapter

0 comments on commit bf99c17

Please sign in to comment.