Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Add documentation for the Redis transport#11341
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
85 changes: 60 additions & 25 deletionsmessenger.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -135,8 +135,12 @@ Transports | ||
| By default, messages are processed as soon as they are dispatched. If you prefer | ||
| to process messages asynchronously, you must configure a transport. These | ||
| transports communicate with your application via queuing systems or third parties. | ||
| There are the following built-in transports: | ||
| - AMQP | ||
| - Doctrine | ||
| - Redis | ||
| .. note:: | ||
| @@ -155,7 +159,7 @@ the messenger component, the following configuration should have been created: | ||
| framework: | ||
| messenger: | ||
| transports: | ||
| your_transport: "%env(MESSENGER_TRANSPORT_DSN)%" | ||
| .. code-block:: xml | ||
| @@ -171,7 +175,7 @@ the messenger component, the following configuration should have been created: | ||
| <framework:config> | ||
| <framework:messenger> | ||
| <framework:transport name="your_transport" dsn="%env(MESSENGER_TRANSPORT_DSN)%"/> | ||
| </framework:messenger> | ||
| </framework:config> | ||
| </container> | ||
| @@ -182,33 +186,63 @@ the messenger component, the following configuration should have been created: | ||
| $container->loadFromExtension('framework', [ | ||
| 'messenger' => [ | ||
| 'transports' => [ | ||
| 'your_transport' => '%env(MESSENGER_TRANSPORT_DSN)%', | ||
| ], | ||
| ], | ||
| ]); | ||
| This will also configure the following services for you: | ||
| #. A ``messenger.sender.your_transport`` sender to be used when routing messages; | ||
| #. A ``messenger.receiver.your_transport`` receiver to be used when consuming messages. | ||
| Now define the ``MESSENGER_TRANSPORT_DSN`` in the ``.env`` file. | ||
| See examples beneath how to configure the DSN for different transports. | ||
| Amqp | ||
| ~~~~ | ||
| .. code-block:: bash | ||
| # .env | ||
| MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages | ||
| This is enough to allow you to route your message to the ``amqp`` transport. | ||
| .. note:: | ||
| In order to use Symfony's built-in AMQP transport, you will need the AMQP | ||
| PHP extension and the Serializercomponent. Ensure that they are installed with: | ||
| .. code-block:: terminal | ||
| $ composer require symfony/amqp-pack | ||
| Redis | ||
| ~~~~~ | ||
| The Redis transport will use `streams`_ to queue messages. | ||
| .. code-block:: bash | ||
| # .env | ||
| MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages | ||
| This is enough to allow you to route your message to the Redis transport. | ||
| If you have multiple systems to receive the same messages you could use different groups | ||
| to achieve this: | ||
| .. code-block:: bash | ||
| # .env | ||
| MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages/group1/consumer1 | ||
| .. note:: | ||
| In order to use Symfony's built-in Redis transport, you will need the Redis | ||
wouterj marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| PHP extension (^4.2), a running Redis server (^5.0) and the Serializer component. | ||
| Routing | ||
| ------- | ||
| @@ -225,7 +259,7 @@ configuration: | ||
| framework: | ||
| messenger: | ||
| routing: | ||
| 'My\Message\Message':your_transport # The name of the defined transport | ||
| .. code-block:: xml | ||
| @@ -242,7 +276,7 @@ configuration: | ||
| <framework:config> | ||
| <framework:messenger> | ||
| <framework:routing message-class="My\Message\Message"> | ||
| <framework:sender service="your_transport"/> | ||
| </framework:routing> | ||
| </framework:messenger> | ||
| </framework:config> | ||
| @@ -254,7 +288,7 @@ configuration: | ||
| $container->loadFromExtension('framework', [ | ||
| 'messenger' => [ | ||
| 'routing' => [ | ||
| 'My\Message\Message' => 'your_transport', | ||
| ], | ||
| ], | ||
| ]); | ||
| @@ -274,7 +308,7 @@ instead of a class name: | ||
| messenger: | ||
| routing: | ||
| 'My\Message\MessageAboutDoingOperationalWork': another_transport | ||
| '*':your_transport | ||
| .. code-block:: xml | ||
| @@ -294,7 +328,7 @@ instead of a class name: | ||
| <framework:sender service="another_transport"/> | ||
| </framework:routing> | ||
| <framework:routing message-class="*"> | ||
| <framework:sender service="your_transport"/> | ||
| </framework:routing> | ||
| </framework:messenger> | ||
| </framework:config> | ||
| @@ -307,7 +341,7 @@ instead of a class name: | ||
| 'messenger' => [ | ||
| 'routing' => [ | ||
| 'My\Message\Message' => 'another_transport', | ||
| '*' => 'your_transport', | ||
| ], | ||
| ], | ||
| ]); | ||
| @@ -322,7 +356,7 @@ A class of messages can also be routed to multiple senders by specifying a list: | ||
| framework: | ||
| messenger: | ||
| routing: | ||
| 'My\Message\ToBeSentToTwoSenders': [your_transport, audit] | ||
| .. code-block:: xml | ||
| @@ -339,7 +373,7 @@ A class of messages can also be routed to multiple senders by specifying a list: | ||
| <framework:config> | ||
| <framework:messenger> | ||
| <framework:routing message-class="My\Message\ToBeSentToTwoSenders"> | ||
| <framework:sender service="your_transport"/> | ||
| <framework:sender service="audit"/> | ||
| </framework:routing> | ||
| </framework:messenger> | ||
| @@ -352,7 +386,7 @@ A class of messages can also be routed to multiple senders by specifying a list: | ||
| $container->loadFromExtension('framework', [ | ||
| 'messenger' => [ | ||
| 'routing' => [ | ||
| 'My\Message\ToBeSentToTwoSenders' => ['your_transport', 'audit'], | ||
| ], | ||
| ], | ||
| ]); | ||
| @@ -369,7 +403,7 @@ while still having them passed to their respective handler: | ||
| messenger: | ||
| routing: | ||
| 'My\Message\ThatIsGoingToBeSentAndHandledLocally': | ||
| senders: [your_transport] | ||
| send_and_handle: true | ||
| .. code-block:: xml | ||
| @@ -387,7 +421,7 @@ while still having them passed to their respective handler: | ||
| <framework:config> | ||
| <framework:messenger> | ||
| <framework:routing message-class="My\Message\ThatIsGoingToBeSentAndHandledLocally" send-and-handle="true"> | ||
| <framework:sender service="your_transport"/> | ||
| </framework:routing> | ||
| </framework:messenger> | ||
| </framework:config> | ||
| @@ -400,7 +434,7 @@ while still having them passed to their respective handler: | ||
| 'messenger' => [ | ||
| 'routing' => [ | ||
| 'My\Message\ThatIsGoingToBeSentAndHandledLocally' => [ | ||
| 'senders' => ['your_transport'], | ||
| 'send_and_handle' => true, | ||
| ], | ||
| ], | ||
| @@ -415,7 +449,7 @@ most of the cases. To do so, use the ``messenger:consume`` command like this: | ||
| .. code-block:: terminal | ||
| $ php bin/console messenger:consumeyour_transport | ||
| The first argument is the receiver's service name. It might have been created by | ||
| your ``transports`` configuration or it can be your own receiver. | ||
| @@ -835,3 +869,4 @@ Learn more | ||
| /messenger/* | ||
| .. _`enqueue's transport`: https://github.com/php-enqueue/messenger-adapter | ||
| .. _`streams`: https://redis.io/topics/streams-intro | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.