-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Symfony Messenger component documentation #9437
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
Changes from 1 commit
585491d
b40bc71
b26de80
88ba8fe
5c828e4
31a56ee
2493c90
bcfae23
25c0b6e
a15752b
fb88abc
509e149
3fb973c
32403ea
c5306b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ Once you've created your handler, you need to register it: | |
.. code-block:: xml | ||
|
||
<service id="App\MessageHandler\MyMessageHandler"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent with other parts of Symfony, could we define an interface for Message Handlers so they can be autoconfigured? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is proposed in the following PR: symfony/symfony#26685. Though, it's controversial :) |
||
<tag name="message_handler" /> | ||
<tag name="messenger.message_handler" /> | ||
</service> | ||
|
||
.. note:: | ||
|
@@ -78,7 +78,7 @@ most of the AMQP brokers such as RabbitMQ. | |
|
||
.. note:: | ||
|
||
If you need more message brokers, you should have a look to Enqueue's adapter | ||
If you need more message brokers, you should have a look to `Enqueue's adapter`_ | ||
which supports things like Kafka, Amazon SQS or Google Pub/Sub. | ||
|
||
An adapter is registered using a "DSN", which is a string that represents the | ||
|
@@ -176,7 +176,47 @@ Learn how to build your own adapters within the Component's documentation. Once | |
you have built your classes, you can register your adapter factory to be able to | ||
use it via a DSN in the Symfony application. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where can I read about how to do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the "Use your adapter" section :) |
||
|
||
Create your adapter Factory | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
You need to give FrameworkBundle the opportunity to create your adapter from a | ||
DSN. You will need an adapter factory:: | ||
|
||
use Symfony\Component\Messenger\Adapter\Factory\AdapterInterface; | ||
use Symfony\Component\Messenger\Adapter\Factory\AdapterFactoryInterface; | ||
|
||
class YourAdapterFactory implements AdapterFactoryInterface | ||
{ | ||
public function create(string $dsn): AdapterInterface | ||
{ | ||
return new YourAdapter(/* ... */); | ||
} | ||
|
||
public function supports(string $dsn): bool | ||
{ | ||
return 0 === strpos($dsn, 'my-adapter://'); | ||
} | ||
} | ||
|
||
The :code:`YourAdaper` class need to implements the :code:`AdapterInterface`. It | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here |
||
will like the following example:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need -> needs or need to -> must and It will be like or It will look like |
||
|
||
use Symfony\Component\Messenger\Adapter\Factory\AdapterInterface; | ||
use Symfony\Component\Messenger\Transport\ReceiverInterface; | ||
use Symfony\Component\Messenger\Transport\SenderInterface; | ||
|
||
class YourAdapter implements AdapterInterface | ||
{ | ||
public function receiver(): ReceiverInterface | ||
{ | ||
return new YourReceiver(/* ... */); | ||
} | ||
|
||
public function sender(): SenderInterface | ||
{ | ||
return new YourSender(/* ... */); | ||
} | ||
} | ||
|
||
Register your factory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
@@ -186,3 +226,24 @@ Register your factory | |
<service id="Your\Adapter\Factory"> | ||
<tag name="messenger.adapter_factory" /> | ||
</service> | ||
|
||
Use your adapter | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Within the :code:`framework.messenger.adapters.*` configuration, create your | ||
named adapter using your own DSN: | ||
|
||
.. code-block:: yaml | ||
|
||
framework: | ||
messenger: | ||
adapters: | ||
yours: 'my-adapter://...' | ||
|
||
This will give you access to the following services: | ||
|
||
1. :code:`messenger.yours_adapter`: the instance of your adapter. | ||
2. :code:`messenger.yours_receiver` and :code:`messenger.yours_sender`, the | ||
receiver and sender created by the adapter. | ||
|
||
.. _`PHP Enqueue bridge`: https://github.com/sroze/enqueue-bridge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize.