@@ -61,7 +61,7 @@ Once you've created your handler, you need to register it:
6161.. code-block :: xml
6262
6363 <service id =" App\MessageHandler\MyMessageHandler" >
64- <tag name =" message_handler" />
64+ <tag name =" messenger. message_handler" />
6565 </service >
6666
6767 .. note ::
@@ -78,7 +78,7 @@ most of the AMQP brokers such as RabbitMQ.
7878
7979.. note ::
8080
81- If you need more message brokers, you should have a look to Enqueue's adapter
81+ If you need more message brokers, you should have a look to ` Enqueue's adapter `_
8282 which supports things like Kafka, Amazon SQS or Google Pub/Sub.
8383
8484An 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
176176you have built your classes, you can register your adapter factory to be able to
177177use it via a DSN in the Symfony application.
178178
179+ Create your adapter Factory
180+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
179181
182+ You need to give FrameworkBundle the opportunity to create your adapter from a
183+ DSN. You will need an adapter factory::
184+
185+ use Symfony\Component\Messenger\Adapter\Factory\AdapterInterface;
186+ use Symfony\Component\Messenger\Adapter\Factory\AdapterFactoryInterface;
187+
188+ class YourAdapterFactory implements AdapterFactoryInterface
189+ {
190+ public function create(string $dsn): AdapterInterface
191+ {
192+ return new YourAdapter(/* ... */);
193+ }
194+
195+ public function supports(string $dsn): bool
196+ {
197+ return 0 === strpos($dsn, 'my-adapter://');
198+ }
199+ }
200+
201+ The :code: `YourAdaper ` class need to implements the :code: `AdapterInterface `. It
202+ will like the following example::
203+
204+ use Symfony\Component\Messenger\Adapter\Factory\AdapterInterface;
205+ use Symfony\Component\Messenger\Transport\ReceiverInterface;
206+ use Symfony\Component\Messenger\Transport\SenderInterface;
207+
208+ class YourAdapter implements AdapterInterface
209+ {
210+ public function receiver(): ReceiverInterface
211+ {
212+ return new YourReceiver(/* ... */);
213+ }
214+
215+ public function sender(): SenderInterface
216+ {
217+ return new YourSender(/* ... */);
218+ }
219+ }
180220
181221Register your factory
182222~~~~~~~~~~~~~~~~~~~~~
@@ -186,3 +226,24 @@ Register your factory
186226 <service id =" Your\Adapter\Factory" >
187227 <tag name =" messenger.adapter_factory" />
188228 </service >
229+
230+ Use your adapter
231+ ~~~~~~~~~~~~~~~~
232+
233+ Within the :code: `framework.messenger.adapters.* ` configuration, create your
234+ named adapter using your own DSN:
235+
236+ .. code-block :: yaml
237+
238+ framework :
239+ messenger :
240+ adapters :
241+ yours : ' my-adapter://...'
242+
243+ This will give you access to the following services:
244+
245+ 1. :code: `messenger.yours_adapter `: the instance of your adapter.
246+ 2. :code: `messenger.yours_receiver ` and :code: `messenger.yours_sender `, the
247+ receiver and sender created by the adapter.
248+
249+ .. _`PHP Enqueue bridge` : https://github.com/sroze/enqueue-bridge
0 commit comments