-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Messenger] Describe the doctrine transport #10616
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
Closed
vincenttouzet
wants to merge
1
commit into
symfony:master
from
vincenttouzet:messenger-doctrine-transport
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
.. index:: | ||
single: Messenger; Use Doctrine as Transport | ||
|
||
Use Doctrine as transport | ||
========================= | ||
|
||
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: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/messenger.yaml | ||
framework: | ||
messenger: | ||
transports: | ||
doctrine: doctrine://default | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/messenger.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony | ||
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:messenger> | ||
<framework:transport name="doctrine" dsn="doctrine://default"/> | ||
</framework:messenger> | ||
</framework:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/messenger.php | ||
$container->loadFromExtension('framework', [ | ||
'messenger' => [ | ||
'transports' => [ | ||
'doctrine' => 'doctrine://default', | ||
], | ||
], | ||
]); | ||
|
||
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``. | ||
|
||
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``. | ||
|
||
Customize Table Name | ||
-------------------- | ||
|
||
By default the transport will create a table named ``messenger_messages`` but you can configure it per transport: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/messenger.yaml | ||
framework: | ||
messenger: | ||
transports: | ||
doctrine: | ||
dsn: doctrine://default?table_name=custom_table_name_for_messages | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/messenger.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony | ||
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:messenger> | ||
<framework:transport name="doctrine" dsn="doctrine://default?table_name=custom_table_name_for_messages"/> | ||
</framework:messenger> | ||
</framework:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/messenger.php | ||
$container->loadFromExtension('framework', [ | ||
'messenger' => [ | ||
'transports' => [ | ||
'doctrine' => [ | ||
'dsn' => 'doctrine://default?table_name=custom_table_name_for_messages', | ||
], | ||
], | ||
], | ||
]); | ||
|
||
Use the same table for different messages | ||
----------------------------------------- | ||
|
||
If you want to store the messages in the same table you can configure the ``queue_name`` option. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/messenger.yaml | ||
framework: | ||
messenger: | ||
transports: | ||
doctrine: | ||
dsn: doctrine://default?queue_name=custom_queue | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/messenger.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony | ||
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:messenger> | ||
<framework:transport name="doctrine" dsn="doctrine://default?queue_name=custom_queue"/> | ||
</framework:messenger> | ||
</framework:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/messenger.php | ||
$container->loadFromExtension('framework', [ | ||
'messenger' => [ | ||
'transports' => [ | ||
'doctrine' => 'doctrine://default?queue_name=custom_queue', | ||
], | ||
], | ||
]); | ||
|
||
Available options | ||
----------------- | ||
|
||
The transport can be configured via DSN or as options. | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# config/packages/messenger.yaml | ||
framework: | ||
messenger: | ||
transports: | ||
doctrine_short: doctrine://default?queue_name=custom_queue | ||
doctrine_full: | ||
dsn: doctrine://default | ||
options: | ||
queue_name: custom_queue | ||
|
||
.. code-block:: xml | ||
|
||
<!-- config/packages/messenger.xml --> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services | ||
https://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony | ||
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:messenger> | ||
<framework:transport name="doctrine_short" dsn="doctrine://default?queue_name=custom_queue"/> | ||
<framework:transport name="doctrine_full" dsn="doctrine://default"> | ||
<framework:option queue_name="custom_queue"/> | ||
</framework:transport> | ||
</framework:messenger> | ||
</framework:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
// config/packages/messenger.php | ||
$container->loadFromExtension('framework', [ | ||
'messenger' => [ | ||
'transports' => [ | ||
'doctrine_short' => 'dsn' => 'doctrine://default?queue_name=custom_queue', | ||
'doctrine_full' => [ | ||
'dsn' => 'doctrine://default', | ||
'options' => [ | ||
'queue_name' => 'custom_queue' | ||
] | ||
], | ||
], | ||
], | ||
]); | ||
|
||
Options defined in the options transport takes precedence over the ones defined in the DSN. | ||
|
||
+-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+ | ||
| Option + Description | Default | | ||
+-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+ | ||
| table_name | Name of the table | messenger_messages | | ||
| queue_name | Name of the queue | default | | ||
| redeliver_timeout | Timeout before redeliver messages still in handling state (i.e: delivered_at is not null and message is still in table). | 3600 | | ||
| auto_setup | Whether the table should be created automatically during send / get. | true | | ||
+-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.