diff --git a/messenger/doctrine-transport.rst b/messenger/doctrine-transport.rst new file mode 100644 index 00000000000..ee2e7060f76 --- /dev/null +++ b/messenger/doctrine-transport.rst @@ -0,0 +1,214 @@ +.. index:: + single: Messenger; Use doctrine as a 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 + + + + + + + + + + + + + .. code-block:: php + + // config/packages/messenger.php + $container->loadFromExtension('framework', array( + 'messenger' => array( + 'transports' => array( + 'doctrine' => 'doctrine://default', + ), + ), + )); + +The format of the DSN is `doctrine://`. 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 + + + + + + + + + + + + + .. code-block:: php + + // config/packages/messenger.php + $container->loadFromExtension('framework', array( + 'messenger' => array( + 'transports' => array( + 'doctrine' => array( + '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 + + + + + + + + + + + + + .. code-block:: php + + // config/packages/messenger.php + $container->loadFromExtension('framework', array( + 'messenger' => array( + 'transports' => array( + 'doctrine' => 'doctrine://default?queue_name=custom_queue', + ), + ), + )); + +Available options +----------------- + +Options for the transport can be configure on the DSN or as options of the transport. + +.. 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 + + + + + + + + + + + + + + + + .. code-block:: php + + // config/packages/messenger.php + $container->loadFromExtension('framework', array( + 'messenger' => array( + 'transports' => array( + 'doctrine_short' => 'dsn' => 'doctrine://default?queue_name=custom_queue', + 'doctrine_full' => array( + 'dsn' => 'doctrine://default', + 'options' => array( + '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 | ++-------------------+--------------------------------------------------------------------------------------------------------------------------+--------------------+