Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 27c0f9d

Browse filesBrowse files
vincenttouzetweaverryan
authored andcommitted
[Messenger] Describe the doctrine tranport
1 parent 5e1033a commit 27c0f9d
Copy full SHA for 27c0f9d

File tree

1 file changed

+214
-0
lines changed
Filter options

1 file changed

+214
-0
lines changed

‎messenger/doctrine-transport.rst

Copy file name to clipboard
+214Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
.. index::
2+
single: Messenger; Use Doctrine as Transport
3+
4+
Use Doctrine as transport
5+
=========================
6+
7+
The Messenger component comes with a Doctrine transport. This lets Doctrine handle the storage of your messages. To use it 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+
https://symfony.com/schema/dic/services/services-1.0.xsd
28+
http://symfony.com/schema/dic/symfony
29+
https://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', [
42+
'messenger' => [
43+
'transports' => [
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+
If you have multiple Doctrine connections defined you can choose the desired one. If you have a connection named ``legacy`` the you should use the following DSN : ``doctrine://legacy``.
52+
53+
Customize Table Name
54+
--------------------
55+
56+
By default the transport will create a table named ``messenger_messages`` but you can configure it per transport:
57+
58+
.. configuration-block::
59+
60+
.. code-block:: yaml
61+
62+
# config/packages/messenger.yaml
63+
framework:
64+
messenger:
65+
transports:
66+
doctrine:
67+
dsn: doctrine://default?table_name=custom_table_name_for_messages
68+
69+
.. code-block:: xml
70+
71+
<!-- config/packages/messenger.xml -->
72+
<?xml version="1.0" encoding="UTF-8" ?>
73+
<container xmlns="http://symfony.com/schema/dic/services"
74+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
75+
xmlns:framework="http://symfony.com/schema/dic/symfony"
76+
xsi:schemaLocation="http://symfony.com/schema/dic/services
77+
https://symfony.com/schema/dic/services/services-1.0.xsd
78+
http://symfony.com/schema/dic/symfony
79+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
80+
81+
<framework:config>
82+
<framework:messenger>
83+
<framework:transport name="doctrine" dsn="doctrine://default?table_name=custom_table_name_for_messages"/>
84+
</framework:messenger>
85+
</framework:config>
86+
</container>
87+
88+
.. code-block:: php
89+
90+
// config/packages/messenger.php
91+
$container->loadFromExtension('framework', [
92+
'messenger' => [
93+
'transports' => [
94+
'doctrine' => [
95+
'dsn' => 'doctrine://default?table_name=custom_table_name_for_messages',
96+
],
97+
],
98+
],
99+
]);
100+
101+
Use the same table for different messages
102+
-----------------------------------------
103+
104+
If you want to store the messages in the same table you can configure the ``queue_name`` option.
105+
106+
.. configuration-block::
107+
108+
.. code-block:: yaml
109+
110+
# config/packages/messenger.yaml
111+
framework:
112+
messenger:
113+
transports:
114+
doctrine:
115+
dsn: doctrine://default?queue_name=custom_queue
116+
117+
.. code-block:: xml
118+
119+
<!-- config/packages/messenger.xml -->
120+
<?xml version="1.0" encoding="UTF-8" ?>
121+
<container xmlns="http://symfony.com/schema/dic/services"
122+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
123+
xmlns:framework="http://symfony.com/schema/dic/symfony"
124+
xsi:schemaLocation="http://symfony.com/schema/dic/services
125+
https://symfony.com/schema/dic/services/services-1.0.xsd
126+
http://symfony.com/schema/dic/symfony
127+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
128+
129+
<framework:config>
130+
<framework:messenger>
131+
<framework:transport name="doctrine" dsn="doctrine://default?queue_name=custom_queue"/>
132+
</framework:messenger>
133+
</framework:config>
134+
</container>
135+
136+
.. code-block:: php
137+
138+
// config/packages/messenger.php
139+
$container->loadFromExtension('framework', [
140+
'messenger' => [
141+
'transports' => [
142+
'doctrine' => 'doctrine://default?queue_name=custom_queue',
143+
],
144+
],
145+
]);
146+
147+
Available options
148+
-----------------
149+
150+
The transport can be configured via DSN or as options.
151+
152+
.. configuration-block::
153+
154+
.. code-block:: yaml
155+
156+
# config/packages/messenger.yaml
157+
framework:
158+
messenger:
159+
transports:
160+
doctrine_short: doctrine://default?queue_name=custom_queue
161+
doctrine_full:
162+
dsn: doctrine://default
163+
options:
164+
queue_name: custom_queue
165+
166+
.. code-block:: xml
167+
168+
<!-- config/packages/messenger.xml -->
169+
<?xml version="1.0" encoding="UTF-8" ?>
170+
<container xmlns="http://symfony.com/schema/dic/services"
171+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
172+
xmlns:framework="http://symfony.com/schema/dic/symfony"
173+
xsi:schemaLocation="http://symfony.com/schema/dic/services
174+
https://symfony.com/schema/dic/services/services-1.0.xsd
175+
http://symfony.com/schema/dic/symfony
176+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
177+
178+
<framework:config>
179+
<framework:messenger>
180+
<framework:transport name="doctrine_short" dsn="doctrine://default?queue_name=custom_queue"/>
181+
<framework:transport name="doctrine_full" dsn="doctrine://default">
182+
<framework:option queue_name="custom_queue"/>
183+
</framework:transport>
184+
</framework:messenger>
185+
</framework:config>
186+
</container>
187+
188+
.. code-block:: php
189+
190+
// config/packages/messenger.php
191+
$container->loadFromExtension('framework', [
192+
'messenger' => [
193+
'transports' => [
194+
'doctrine_short' => 'dsn' => 'doctrine://default?queue_name=custom_queue',
195+
'doctrine_full' => [
196+
'dsn' => 'doctrine://default',
197+
'options' => [
198+
'queue_name' => 'custom_queue'
199+
]
200+
],
201+
],
202+
],
203+
]);
204+
205+
Options defined in the options transport takes precedence over the ones defined in the DSN.
206+
207+
+-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+
208+
| Option + Description | Default |
209+
+-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+
210+
| table_name | Name of the table | messenger_messages |
211+
| queue_name | Name of the queue | default |
212+
| redeliver_timeout | Timeout before redeliver messages still in handling state (i.e: delivered_at is not null and message is still in table). | 3600 |
213+
| auto_setup | Whether the table should be created automatically during send / get. | true |
214+
+-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.