Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit77fcfef

Browse files
committed
[Messenger] Multiples buses, scoping handlers per bus, PSR-4 discovery & debug
1 parent6d8657b commit77fcfef

File tree

4 files changed

+306
-147
lines changed

4 files changed

+306
-147
lines changed

‎components/messenger.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,15 @@ loop, the message bus will add a :class:`Symfony\\Component\\Messenger\\Asynchro
262262
envelope item to the message envelopes and the:class:`Symfony\\Component\\Messenger\\Asynchronous\\Middleware\\SendMessageMiddleware`
263263
middleware will know it should not route these messages again to a transport.
264264

265+
266+
Learn more
267+
----------
268+
..toctree::
269+
:maxdepth:1
270+
:glob:
271+
272+
/messenger
273+
/messenger/*
274+
265275
.. _blog posts about command buses:https://matthiasnoback.nl/tags/command%20bus/
266276
.. _SimpleBus project:http://simplebus.io

‎messenger.rst‎

Lines changed: 8 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -419,112 +419,6 @@ like this:
419419
The first argument is the receiver's service name. It might have been created by
420420
your ``transports`` configuration or it can be your own receiver.
421421

422-
Multiple Buses
423-
--------------
424-
425-
If you are interested in architectures like CQRS, you might want to have multiple
426-
buses within your application.
427-
428-
You can create multiple buses (in this example, a command bus and an event bus) like
429-
this:
430-
431-
..configuration-block::
432-
433-
..code-block::yaml
434-
435-
# config/packages/messenger.yaml
436-
framework:
437-
messenger:
438-
# The bus that is going to be injected when injecting MessageBusInterface:
439-
default_bus:messenger.bus.commands
440-
441-
# Create buses
442-
buses:
443-
messenger.bus.commands:~
444-
messenger.bus.events:~
445-
446-
..code-block::xml
447-
448-
<!-- config/packages/messenger.xml-->
449-
<?xml version="1.0" encoding="UTF-8" ?>
450-
<containerxmlns="http://symfony.com/schema/dic/services"
451-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
452-
xmlns:framework="http://symfony.com/schema/dic/symfony"
453-
xsi:schemaLocation="http://symfony.com/schema/dic/services
454-
http://symfony.com/schema/dic/services/services-1.0.xsd
455-
http://symfony.com/schema/dic/symfony
456-
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
457-
458-
<framework:config>
459-
<framework:messengerdefault-bus="messenger.bus.commands">
460-
<framework:busname="messenger.bus.commands" />
461-
<framework:busname="messenger.bus.events" />
462-
</framework:messenger>
463-
</framework:config>
464-
</container>
465-
466-
..code-block::php
467-
468-
// config/packages/messenger.php
469-
$container->loadFromExtension('framework', array(
470-
'messenger' => array(
471-
'default_bus' => 'messenger.bus.commands',
472-
'buses' => array(
473-
'messenger.bus.commands' => null,
474-
'messenger.bus.events' => null,
475-
),
476-
),
477-
));
478-
479-
This will generate the ``messenger.bus.commands`` and ``messenger.bus.events`` services
480-
that you can inject in your services.
481-
482-
..note::
483-
484-
To register a handler only for a specific bus, add a ``bus`` attribute to
485-
the handler's service tag (``messenger.message_handler``) and use the bus
486-
name as its value.
487-
488-
Type-hints and Auto-wiring
489-
~~~~~~~~~~~~~~~~~~~~~~~~~~
490-
491-
Auto-wiring is a great feature that allows you to reduce the amount of configuration
492-
required for your service container to be created. When using multiple buses, by default,
493-
the auto-wiring will not work as it won't know which bus to inject in your own services.
494-
495-
In order to clarify this, you can use the DependencyInjection's binding capabilities
496-
to clarify which bus will be injected based on the argument's name:
497-
498-
..configuration-block::
499-
500-
..code-block::yaml
501-
502-
# config/services.yaml
503-
services:
504-
_defaults:
505-
# ...
506-
507-
bind:
508-
$commandBus:'@messenger.bus.commands'
509-
$eventBus:'@messenger.bus.events'
510-
511-
..code-block::xml
512-
513-
<!-- config/services.xml-->
514-
<?xml version="1.0" encoding="UTF-8" ?>
515-
<containerxmlns="http://symfony.com/schema/dic/services"
516-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
517-
xsi:schemaLocation="http://symfony.com/schema/dic/services
518-
http://symfony.com/schema/dic/services/services-1.0.xsd">
519-
520-
<services>
521-
<defaults>
522-
<bindkey="$commandBus"type="service"id="messenger.bus.commands" />
523-
<bindkey="$commandBus"type="service"id="messenger.bus.events" />
524-
</defaults>
525-
</services>
526-
</container>
527-
528422
Middleware
529423
----------
530424

@@ -959,4 +853,12 @@ will give you access to the following services:
959853
#. ``messenger.sender.yours``: the sender;
960854
#. ``messenger.receiver.yours``: the receiver.
961855

856+
Learn more
857+
----------
858+
..toctree::
859+
:maxdepth:1
860+
:glob:
861+
862+
/messenger/*
863+
962864
.. _`enqueue's transport`:https://github.com/php-enqueue/messenger-adapter

‎messenger/multiple-buses.rst‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp