Skip to content

Commit 5a19dd2

Browse files
committed
[Messenger] Describe the doctrine tranport
1 parent d3c8438 commit 5a19dd2

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

messenger.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,4 +936,13 @@ will give you access to the following services:
936936
#. ``messenger.sender.yours``: the sender;
937937
#. ``messenger.receiver.yours``: the receiver.
938938

939+
Learn More
940+
----------
941+
942+
.. toctree::
943+
:maxdepth: 1
944+
:glob:
945+
946+
messenger/*
947+
939948
.. _`enqueue's transport`: https://github.com/php-enqueue/messenger-adapter

messenger/doctrine-transport.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.. index::
2+
single: Messenger; Use doctrine as a transport
3+
4+
Use Doctrine as transport
5+
=========================
6+
7+
The Messenger component comes with a Doctrine transport. This transport let doctrine handle the storage of your messages. To use this transport you need to define the transport as the following :
8+
9+
.. configuration-block::
10+
11+
.. code-block:: yaml
12+
13+
# config/packages/messenger.yaml
14+
framework:
15+
messenger:
16+
transports:
17+
doctrine: "doctrine://default"
18+
19+
.. code-block:: xml
20+
21+
<!-- config/packages/messenger.xml -->
22+
<?xml version="1.0" encoding="UTF-8" ?>
23+
<container xmlns="http://symfony.com/schema/dic/services"
24+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25+
xmlns:framework="http://symfony.com/schema/dic/symfony"
26+
xsi:schemaLocation="http://symfony.com/schema/dic/services
27+
http://symfony.com/schema/dic/services/services-1.0.xsd
28+
http://symfony.com/schema/dic/symfony
29+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
30+
31+
<framework:config>
32+
<framework:messenger>
33+
<framework:transport name="doctrine" dsn="doctrine://default" />
34+
</framework:messenger>
35+
</framework:config>
36+
</container>
37+
38+
.. code-block:: php
39+
40+
// config/packages/messenger.php
41+
$container->loadFromExtension('framework', array(
42+
'messenger' => array(
43+
'transports' => array(
44+
'doctrine' => 'doctrine://default',
45+
),
46+
),
47+
));
48+
49+
The format of the DSN is `doctrine://<connection_name>`. The connection name is the name you used in the doctrine configuration. If you only use one connection then use `default`.
50+
51+
Customize table name
52+
--------------------
53+
54+
By default the transport will create a table named `messenger_messages` but you can configure it per transport:
55+
56+
.. configuration-block::
57+
58+
.. code-block:: yaml
59+
60+
# config/packages/messenger.yaml
61+
framework:
62+
messenger:
63+
transports:
64+
doctrine:
65+
dsn: "doctrine://default"
66+
options: {table_name: "custom_table_name_for_messages"}
67+
68+
.. code-block:: xml
69+
70+
<!-- config/packages/messenger.xml -->
71+
<?xml version="1.0" encoding="UTF-8" ?>
72+
<container xmlns="http://symfony.com/schema/dic/services"
73+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74+
xmlns:framework="http://symfony.com/schema/dic/symfony"
75+
xsi:schemaLocation="http://symfony.com/schema/dic/services
76+
http://symfony.com/schema/dic/services/services-1.0.xsd
77+
http://symfony.com/schema/dic/symfony
78+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
79+
80+
<framework:config>
81+
<framework:messenger>
82+
<framework:transport name="doctrine" dsn="doctrine://default">
83+
<framework:option table_name="custom_table_name_for_messages" />
84+
</framework:transport>
85+
</framework:messenger>
86+
</framework:config>
87+
</container>
88+
89+
.. code-block:: php
90+
91+
// config/packages/messenger.php
92+
$container->loadFromExtension('framework', array(
93+
'messenger' => array(
94+
'transports' => array(
95+
'doctrine' => array(
96+
'dsn' => 'doctrine://default',
97+
'options' => array('table_name' => 'custom_table_name_for_messages'),
98+
),
99+
),
100+
),
101+
));
102+
103+
Working with multiple connections
104+
---------------------------------
105+
106+
If you have multiple Doctrine connections defined you can choose the desired one. If you have a connection named `legacy` the you must use the following DSN : `doctrine://legacy`.

0 commit comments

Comments
 (0)