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

Commit0604511

Browse files
committed
[Messenger] Backport some changes from 4.2 branch
1 parentb9768c7 commit0604511

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

‎components/messenger.rst‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Concepts
3838
something can be a message broker or a third party API for example.
3939

4040
**Receiver**:
41-
Responsible for deserializing and forwarding messages to handler(s). This
42-
can be a message queue puller or an API endpoint for example.
41+
Responsible forretrieving,deserializing and forwarding messages to handler(s).
42+
Thiscan be a message queue puller or an API endpoint for example.
4343

4444
**Handler**:
4545
Responsible for handling messages using the business logic applicable to the messages.
@@ -55,7 +55,7 @@ are configured for you:
5555

5656
#. ``LoggingMiddleware`` (logs the processing of your messages)
5757
#. ``SendMessageMiddleware`` (enables asynchronous processing)
58-
#. ``HandleMessageMiddleware`` (calls the registeredhandle)
58+
#. ``HandleMessageMiddleware`` (calls the registeredhandler)
5959

6060
Example::
6161

@@ -206,7 +206,7 @@ First, create your sender::
206206
Your own Receiver
207207
~~~~~~~~~~~~~~~~~
208208

209-
A receiver is responsible forreceiving messages from a source and dispatching
209+
A receiver is responsible forgetting messages from a source and dispatching
210210
them to the application.
211211

212212
Imagine you already processed some "orders" in your application using a
@@ -226,7 +226,7 @@ First, create your receiver::
226226
use Symfony\Component\Serializer\SerializerInterface;
227227
use Symfony\Component\Messenger\Envelope;
228228

229-
classNewOrdersFromCsvFile implements ReceiverInterface
229+
classNewOrdersFromCsvFileReceiver implements ReceiverInterface
230230
{
231231
private $serializer;
232232
private $filePath;

‎messenger.rst‎

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ message handler. It's a class with an ``__invoke`` method::
8484

8585
Message handlers must be registered as services and:doc:`tagged</service_container/tags>`
8686
with the ``messenger.message_handler`` tag. If you're using the
87-
:ref:`default services.yaml configuration<service-container-services-load-example>`,
87+
:ref:`default services.yaml configuration<service-container-services-load-example>` and implement
88+
:class:`Symfony\\Component\\Messenger\\Handler\\MessageHandlerInterface`
89+
or:class:`Symfony\\Component\\Messenger\\Handler\\MessageSubscriberInterface`,
8890
this is already done for you, thanks to:ref:`autoconfiguration<services-autoconfigure>`.
8991

9092
If you're not using service autoconfiguration, then you need to add this config:
@@ -543,11 +545,16 @@ for each bus looks like this:
543545
#. ``call_message_handler`` middleware. Will call the message handler(s) for the
544546
given message.
545547

546-
Adding your own Middleware
547-
~~~~~~~~~~~~~~~~~~~~~~~~~~
548+
..note::
548549

549-
As described in the component documentation, you can add your own middleware
550-
within the buses to add some extra capabilities like this:
550+
These middleware names are actually shortcuts working by convention.
551+
The real service ids are prefixed with the ``messenger.middleware.`` namespace.
552+
553+
Disabling default Middleware
554+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
555+
556+
If you don't want the default collection of middleware to be present on your bus,
557+
you can disable them like this:
551558

552559
..configuration-block::
553560

@@ -558,9 +565,7 @@ within the buses to add some extra capabilities like this:
558565
messenger:
559566
buses:
560567
messenger.bus.default:
561-
middleware:
562-
-'App\Middleware\MyMiddleware'
563-
-'App\Middleware\AnotherMiddleware'
568+
default_middleware:false
564569
565570
..code-block::xml
566571
@@ -576,10 +581,7 @@ within the buses to add some extra capabilities like this:
576581
577582
<framework:config>
578583
<framework:messenger>
579-
<framework:busname="messenger.bus.default">
580-
<framework:middlewareid="App\Middleware\MyMiddleware" />
581-
<framework:middlewareid="App\Middleware\AnotherMiddleware" />
582-
</framework:bus>
584+
<framework:busname="messenger.bus.default"default-middleware="false" />
583585
</framework:messenger>
584586
</framework:config>
585587
</container>
@@ -591,23 +593,17 @@ within the buses to add some extra capabilities like this:
591593
'messenger' => array(
592594
'buses' => array(
593595
'messenger.bus.default' => array(
594-
'middleware' => array(
595-
'App\Middleware\MyMiddleware',
596-
'App\Middleware\AnotherMiddleware',
597-
),
596+
'default_middleware' => false,
598597
),
599598
),
600599
),
601600
));
602601
603-
Note that if the service is abstract, a different instance of service will be
604-
created per bus.
605-
606-
Disabling default Middleware
607-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
602+
Adding your own Middleware
603+
~~~~~~~~~~~~~~~~~~~~~~~~~~
608604

609-
If you don't wantthedefault collection of middleware to be present onyourbus,
610-
you can disable them like this:
605+
As described inthecomponent documentation, you can addyourown middleware
606+
within the buses to add some extra capabilities like this:
611607

612608
..configuration-block::
613609

@@ -618,7 +614,9 @@ you can disable them like this:
618614
messenger:
619615
buses:
620616
messenger.bus.default:
621-
default_middleware:false
617+
middleware:
618+
-'App\Middleware\MyMiddleware'
619+
-'App\Middleware\AnotherMiddleware'
622620
623621
..code-block::xml
624622
@@ -634,7 +632,10 @@ you can disable them like this:
634632
635633
<framework:config>
636634
<framework:messenger>
637-
<framework:busname="messenger.bus.default"default-middleware="false" />
635+
<framework:busname="messenger.bus.default">
636+
<framework:middlewareid="App\Middleware\MyMiddleware" />
637+
<framework:middlewareid="App\Middleware\AnotherMiddleware" />
638+
</framework:bus>
638639
</framework:messenger>
639640
</framework:config>
640641
</container>
@@ -646,12 +647,18 @@ you can disable them like this:
646647
'messenger' => array(
647648
'buses' => array(
648649
'messenger.bus.default' => array(
649-
'default_middleware' => false,
650+
'middleware' => array(
651+
'App\Middleware\MyMiddleware',
652+
'App\Middleware\AnotherMiddleware',
653+
),
650654
),
651655
),
652656
),
653657
));
654658
659+
Note that if the service is abstract, a different instance of service will be
660+
created per bus.
661+
655662
Using Middleware Factories
656663
~~~~~~~~~~~~~~~~~~~~~~~~~~
657664

@@ -674,13 +681,13 @@ factories. Defining such requires a two-step configuration based on Symfony's
674681
675682
# Step 2: an abstract definition that will call the factory with default
676683
# arguments or the ones provided in the middleware config
677-
messenger.middleware.doctrine_transaction_middleware:
684+
messenger.middleware.doctrine_transaction:
678685
class:Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
679686
factory:'doctrine.orm.messenger.middleware_factory.transaction:createMiddleware'
680687
abstract:true
681688
# the default arguments to use when none provided from config. Example:
682689
# middleware:
683-
# -doctrine_transaction_middleware: ~
690+
# -doctrine_transaction: ~
684691
arguments:['default']
685692
686693
..code-block::xml
@@ -703,7 +710,7 @@ factories. Defining such requires a two-step configuration based on Symfony's
703710
704711
<!-- Step 2: an abstract definition that will call the factory with default
705712
arguments or the ones provided in the middleware config-->
706-
<serviceid="messenger.middleware.doctrine_transaction_middleware"
713+
<serviceid="messenger.middleware.doctrine_transaction"
707714
class="Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware"
708715
abstract="true">
709716
@@ -729,7 +736,7 @@ factories. Defining such requires a two-step configuration based on Symfony's
729736
730737
// Step 2: an abstract definition that will call the factory with default
731738
// arguments or the ones provided in the middleware config
732-
$container->register('messenger.middleware.doctrine_transaction_middleware', DoctrineTransactionMiddleware::class)
739+
$container->register('messenger.middleware.doctrine_transaction', DoctrineTransactionMiddleware::class)
733740
->setFactory(array(
734741
new Reference('doctrine.orm.messenger.middleware_factory.transaction'),
735742
'createMiddleware'
@@ -742,7 +749,7 @@ which is the argument expected by the
742749
``Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory::createMiddleware`` method.
743750

744751
Then you can reference and configure the
745-
``messenger.middleware.doctrine_transaction_middleware`` service as a middleware:
752+
``messenger.middleware.doctrine_transaction`` service as a middleware:
746753

747754
..configuration-block::
748755

@@ -755,9 +762,9 @@ Then you can reference and configure the
755762
command_bus:
756763
middleware:
757764
# Using defaults
758-
-doctrine_transaction_middleware
765+
-doctrine_transaction
759766
# Using another entity manager
760-
-doctrine_transaction_middleware:['custom']
767+
-doctrine_transaction:['custom']
761768
762769
..code-block::xml
763770
@@ -775,9 +782,9 @@ Then you can reference and configure the
775782
<framework:messenger>
776783
<framework:busname="command_bus">
777784
<!-- Using defaults-->
778-
<framework:middlewareid="doctrine_transaction_middleware" />
785+
<framework:middlewareid="doctrine_transaction" />
779786
<!-- Using another entity manager-->
780-
<framework:middlewareid="doctrine_transaction_middleware">
787+
<framework:middlewareid="doctrine_transaction">
781788
<framework:argument>custom</framework:argument>
782789
</framework:middleware>
783790
</framework:bus>
@@ -794,20 +801,15 @@ Then you can reference and configure the
794801
'command_bus' => array(
795802
'middleware' => array(
796803
// Using defaults
797-
'doctrine_transaction_middleware',
804+
'doctrine_transaction',
798805
// Using another entity manager
799-
array('id' => 'doctrine_transaction_middleware', 'arguments' => array('custom')),
806+
array('id' => 'doctrine_transaction', 'arguments' => array('custom')),
800807
),
801808
),
802809
),
803810
),
804811
));
805812
806-
..note::
807-
808-
The ``doctrine_transaction_middleware`` shortcut is a convention. The real
809-
service id is prefixed with the ``messenger.middleware.`` namespace.
810-
811813
..note::
812814

813815
Middleware factories only allow scalar and array arguments in config (no
@@ -816,9 +818,9 @@ Then you can reference and configure the
816818

817819
..tip::
818820

819-
The ``doctrine_transaction_middleware`` is a built-in middleware wired
820-
automatically when the DoctrineBundle and the Messenger component are
821-
installed and enabled.
821+
The ``messenger.middleware.doctrine_transaction``middlewareis a built-in
822+
middleware wiredautomatically when the DoctrineBundle and the Messenger
823+
component areinstalled and enabled.
822824

823825
Your own Transport
824826
------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp