@@ -61,7 +61,7 @@ Once you've created your handler, you need to register it:
61
61
.. code-block :: xml
62
62
63
63
<service id =" App\MessageHandler\MyMessageHandler" >
64
- <tag name =" message_handler" />
64
+ <tag name =" messenger. message_handler" />
65
65
</service >
66
66
67
67
.. note ::
@@ -78,7 +78,7 @@ most of the AMQP brokers such as RabbitMQ.
78
78
79
79
.. note ::
80
80
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 `_
82
82
which supports things like Kafka, Amazon SQS or Google Pub/Sub.
83
83
84
84
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
176
176
you have built your classes, you can register your adapter factory to be able to
177
177
use it via a DSN in the Symfony application.
178
178
179
+ Create your adapter Factory
180
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
179
181
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
+ }
180
220
181
221
Register your factory
182
222
~~~~~~~~~~~~~~~~~~~~~
@@ -186,3 +226,24 @@ Register your factory
186
226
<service id =" Your\Adapter\Factory" >
187
227
<tag name =" messenger.adapter_factory" />
188
228
</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