8000 symfony-docs/messenger.rst at 4.1 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":".github","path":".github","contentType":"directory"},{"name":".symfony","path":".symfony","contentType":"directory"},{"name":"_build","path":"_build","contentType":"directory"},{"name":"_images","path":"_images","contentType":"directory"},{"name":"_includes","path":"_includes","contentType":"directory"},{"name":"best_practices","path":"best_practices","contentType":"directory"},{"name":"bundles","path":"bundles","contentType":"directory"},{"name":"components","path":"components","contentType":"directory"},{"name":"configuration","path":"configuration","contentType":"directory"},{"name":"console","path":"console","contentType":"directory"},{"name":"contributing","path":"contributing","contentType":"directory"},{"name":"controller","path":"controller","contentType":"directory"},{"name":"create_framework","path":"create_framework","contentType":"directory"},{"name":"deployment","path":"deployment","contentType":"directory"},{"name":"doctrine","path":"doctrine","contentType":"directory"},{"name":"email","path":"email","contentType":"directory"},{"name":"event_dispatcher","path":"event_dispatcher","contentType":"directory"},{"name":"form","path":"form","contentType":"directory"},{"name":"frontend","path":"frontend","contentType":"directory"},{"name":"getting_started","path":"getting_started","contentType":"directory"},{"name":"http_cache","path":"http_cache","contentType":"directory"},{"name":"introduction","path":"introduction","contentType":"directory"},{"name":"logging","path":"logging","contentType":"directory"},{"name":"messenger","path":"messenger","contentType":"directory"},{"name":"profiler","path":"profiler","contentType":"directory"},{"name":"quick_tour","path":"quick_tour","contentType":"directory"},{"name":"reference","path":"reference","contentType":"directory"},{"name":"routing","path":"routing","contentType":"directory"},{"name":"security","path":"security","contentType":"directory"},{"name":"serializer","path":"serializer","contentType":"directory"},{"name":"service_container","path":"service_container","contentType":"directory"},{"name":"session","path":"session","contentType":"directory"},{"name":"setup","path":"setup","contentType":"directory"},{"name":"templating","path":"templating","contentType":"directory"},{"name":"testing","path":"testing","contentType":"directory"},{"name":"translation","path":"translation","contentType":"directory"},{"name":"validation","path":"validation","contentType":"directory"},{"name":"workflow","path":"workflow","contentType":"directory"},{"name":".editorconfig","path":".editorconfig","contentType":"file"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".symfony.cloud.yaml","path":".symfony.cloud.yaml","contentType":"file"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"Dockerfile","path":"Dockerfile","contentType":"file"},{"name":"README.markdown","path":"README.markdown","contentType":"file"},{"name":"bundles.rst","path":"bundles.rst","contentType":"file"},{"name":"configuration.rst","path":"configuration.rst","contentType":"file"},{"name":"console.rst","path":"console.rst","contentType":"file"},{"name":"controller.rst","path":"controller.rst","contentType":"file"},{"name":"deployment.rst","path":"deployment.rst","contentType":"file"},{"name":"doctrine.rst","path":"doctrine.rst","contentType":"file"},{"name":"email.rst","path":"email.rst","contentType":"file"},{"name":"event_dispatcher.rst","path":"event_dispatcher.rst","contentType":"file"},{"name":"forms.rst","path":"forms.rst","contentType":"file"},{"name":"frontend.rst","path":"frontend.rst","contentType":"file"},{"name":"http_cache.rst","path":"http_cache.rst","contentType":"file"},{"name":"index.rst","path":"index.rst","contentType":"file"},{"name":"logging.rst","path":"logging.rst","contentType":"file"},{"name":"messenger.rst","path":"messenger.rst","contentType":"file"},{"name":"page_creation.rst","path":"page_creation.rst","contentType":"file"},{"name":"performance.rst","path":"performance.rst","contentType":"file"},{"name":"profiler.rst","path":"profiler.rst","contentType":"file"},{"name":"routing.rst","path":"routing.rst","contentType":"file"},{"name":"security.rst","path":"security.rst","contentType":"file"},{"name":"serializer.rst","path":"serializer.rst","contentType":"file"},{"name":"service_container.rst","path":"service_container.rst","contentType":"file"},{"name":"session.rst","path":"session.rst","contentType":"file"},{"name":"setup.rst","path":"setup.rst","contentType":"file"},{"name":"templating.rst","path":"templating.rst","contentType":"file"},{"name":"testing.rst","path":"testing.rst","contentType":"file"},{"name":"translation.rst","path":"translation.rst","contentType":"file"},{"name":"validation.rst","path":"validation.rst","contentType":"file"},{"name":"web_link.rst","path":"web_link.rst","contentType":"file"},{"name":"workflow.rst","path":"workflow.rst","contentType":"file"}],"totalCount":73}},"fileTreeProcessingTime":5.068172000000001,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":521583,"defaultBranch":"7.3","name":"symfony-docs","ownerLogin":"symfony","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2010-02-17T08:43:51.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/143937?v=4","public":true,"private":false,"isOrgOwned":true},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"4.1","listCacheKey":"v0:1748857018.0","canEdit":false,"refType":"branch","currentOid":"5b918a281ee0087e8afa3421372456c841beab09"},"path":"messenger.rst","currentUser":null,"blob":{"rawLines":null,"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/symfony/symfony-docs/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"messenger.rst","displayUrl":"https://github.com/symfony/symfony-docs/blob/4.1/messenger.rst?raw=true","headerInfo":{"blobSize":"29.7 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"9ac8ffc","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fsymfony%2Fsymfony-docs%2Fblob%2F4.1%2Fmessenger.rst","isCSV":false,"isRichtext":true,"toc":[{"level":2,"text":"How to Use the Messenger","anchor":"how-to-use-the-messenger","htmlText":"How to Use the Messenger"},{"level":3,"text":"Installation","anchor":"installation","htmlText":"Installation"},{"level":3,"text":"Message","anchor":"message","htmlText":"Message"},{"level":3,"text":"Using the Messenger Service","anchor":"using-the-messenger-service","htmlText":"Using the Messenger Service"},{"level":3,"text":"Registering Handlers","anchor":"registering-handlers","htmlText":"Registering Handlers"},{"level":3,"text":"Transports","anchor":"transports","htmlText":"Transports"},{"level":3,"text":"Routing","anchor":"routing","htmlText":"Routing"},{"level":3,"text":"Consuming Messages","anchor":"consuming-messages","htmlText":"Consuming Messages"},{"level":3,"text":"Middleware","anchor":"middleware","htmlText":"Middleware"},{"level":4,"text":"Disabling default Middleware","anchor":"disabling-default-middleware","htmlText":"Disabling default Middleware"},{"level":4,"text":"Adding your own Middleware","anchor":"adding-your-own-middleware","htmlText":"Adding your own Middleware"},{"level":4,"text":"Using Middleware Factories","anchor":"using-middleware-factories","htmlText":"Using Middleware Factories"},{"level":3,"text":"Your own Transport","anchor":"your-own-transport","htmlText":"Your own Transport"},{"level":4,"text":"Create your Transport Factory","anchor":"create-your-transport-factory","htmlText":"Create your Transport Factory"},{"level":4,"text":"Register your Factory","anchor":"register-your-factory","htmlText":"Register your Factory"},{"level":4,"text":"Use your Transport","anchor":"use-your-transport","htmlText":"Use your Transport"},{"level":3,"text":"Learn more","anchor":"learn-more","htmlText":"Learn more"}],"lineInfo":{"truncatedLoc":"866","truncatedSloc":"671"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"reStructuredText","languageID":419,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/symfony/symfony-docs/blob/4.1/messenger.rst","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/symfony/symfony-docs/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/symfony/symfony-docs/raw/refs/heads/4.1/messenger.rst","renderImageOrRaw":false,"richText":"\u003carticle class=\"markdown-body entry-content container-lg\" itemprop=\"text\"\u003e\u003cpre\u003e.. index::\n single: Messenger\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-how-to-use-the-messenger\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eHow to Use the Messenger\u003c/h2\u003e\u003ca id=\"user-content-how-to-use-the-messenger\" class=\"anchor\" aria-label=\"Permalink: How to Use the Messenger\" href=\"#how-to-use-the-messenger\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eSymfony's Messenger provides a message bus and some routing capabilities to send\nmessages within your application and through transports such as message queues.\nBefore using it, read the \u003ca href=\"#id1\"\u003e\u003cspan id=\"user-content-id2\"\u003e:doc:`Messenger component docs \u0026lt;/components/messenger\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nto get familiar with its concepts.\u003c/p\u003e\n\u003ca name=\"user-content-installation\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eInstallation\u003c/h3\u003e\u003ca id=\"user-content-installation\" class=\"anchor\" aria-label=\"Permalink: Installation\" href=\"#installation\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eIn applications using \u003ca href=\"#id3\"\u003e\u003cspan id=\"user-content-id4\"\u003e:doc:`Symfony Flex \u0026lt;/setup/flex\u0026gt;`\u003c/span\u003e\u003c/a\u003e, run this command to\ninstall messenger before using it:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ composer require messenger\n\u003c/pre\u003e\n\u003ca name=\"user-content-message\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eMessage\u003c/h3\u003e\u003ca id=\"user-content-message\" class=\"anchor\" aria-label=\"Permalink: Message\" href=\"#message\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eBefore you can send a message, you must create it first. There is no specific\nrequirement for a message, except it should be serializable and unserializable\nby a Symfony Serializer instance:\u003c/p\u003e\n\u003cpre\u003e// src/Message/SmsNotification.php\nnamespace App\\Message;\n\nclass SmsNotification\n{\n private $content;\n\n public function __construct(string $content)\n {\n $this-\u0026gt;content = $content;\n }\n\n // ...getters\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-using-the-messenger-service\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eUsing the Messenger Service\u003c/h3\u003e\u003ca id=\"user-content-using-the-messenger-service\" class=\"anchor\" aria-label=\"Permalink: Using the Messenger Service\" href=\"#using-the-messenger-service\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eOnce enabled, the \u003ccode\u003emessage_bus\u003c/code\u003e service can be injected in any service where\nyou need it, like in a controller:\u003c/p\u003e\n\u003cpre\u003e// src/Controller/DefaultController.php\nnamespace App\\Controller;\n\nuse App\\Message\\SmsNotification;\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController;\nuse Symfony\\Component\\Messenger\\MessageBusInterface;\n\nclass DefaultController extends AbstractController\n{\n public function index(MessageBusInterface $bus)\n {\n $bus-\u0026gt;dispatch(new SmsNotification('A string to be sent...'));\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-registering-handlers\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRegistering Handlers\u003c/h3\u003e\u003ca id=\"user-content-registering-handlers\" class=\"anchor\" aria-label=\"Permalink: Registering Handlers\" href=\"#registering-handlers\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eIn order to do something when your message is dispatched, you need to create a\nmessage handler. It's a class with an \u003ccode\u003e__invoke\u003c/code\u003e method:\u003c/p\u003e\n\u003cpre\u003e// src/MessageHandler/SmsNotificationHandler.php\nnamespace App\\MessageHandler;\n\nuse App\\Message\\SmsNotification;\nuse Symfony\\Component\\Messenger\\Handler\\MessageHandlerInterface;\n\nclass SmsNotificationHandler implements MessageHandlerInterface\n{\n public function __invoke(SmsNotification $message)\n {\n // do something with it.\n }\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eMessage handlers must be registered as services and \u003ca href=\"#id5\"\u003e\u003cspan id=\"user-content-id6\"\u003e:doc:`tagged \u0026lt;/service_container/tags\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nwith the \u003ccode\u003emessenger.message_handler\u003c/code\u003e tag. If you're using the\n\u003ca href=\"#id7\"\u003e\u003cspan id=\"user-content-id8\"\u003e:ref:`default services.yaml configuration \u0026lt;service-container-services-load-example\u0026gt;`\u003c/span\u003e\u003c/a\u003e and implement\n\u003ca href=\"#id9\"\u003e\u003cspan id=\"user-content-id10\"\u003e:class:`Symfony\\\\Component\\\\Messenger\\\\Handler\\\\MessageHandlerInterface`\u003c/span\u003e\u003c/a\u003e\nor \u003ca href=\"#id11\"\u003e\u003cspan id=\"user-content-id12\"\u003e:class:`Symfony\\\\Component\\\\Messenger\\\\Handler\\\\MessageSubscriberInterface`\u003c/span\u003e\u003c/a\u003e,\nthis is already done for you, thanks to \u003ca href=\"#id13\"\u003e\u003cspan id=\"user-content-id14\"\u003e:ref:`autoconfiguration \u0026lt;services-autoconfigure\u0026gt;`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you're not using service autoconfiguration, then you need to add this config:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/services.yaml\n services:\n App\\MessageHandler\\SmsNotificationHandler:\n tags: [messenger.message_handler]\n\n .. code-block:: xml\n\n \u0026lt;!-- config/services.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\"\u0026gt;\n\n \u0026lt;services\u0026gt;\n \u0026lt;service id=\"App\\MessageHandler\\SmsNotificationHandler\"\u0026gt;\n \u0026lt;tag name=\"messenger.message_handler\" /\u0026gt;\n \u0026lt;/service\u0026gt;\n \u0026lt;/services\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/services.php\n use App\\MessageHandler\\SmsNotificationHandler;\n\n $container-\u0026gt;register(SmsNotificationHandler::class)\n -\u0026gt;addTag('messenger.message_handler');\n\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf the message cannot be guessed from the handler's type-hint, use the\n\u003ccode\u003ehandles\u003c/code\u003e attribute on the tag.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-transports\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eTransports\u003c/h3\u003e\u003ca id=\"user-content-transports\" class=\"anchor\" aria-label=\"Permalink: Transports\" href=\"#transports\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eBy default, messages are processed as soon as they are dispatched. If you prefer\nto process messages asynchronously, you must configure a transport. These\ntransports communicate with your application via queuing systems or third parties.\nThe built-in AMQP transport allows you to communicate with most of the AMQP\nbrokers such as RabbitMQ.\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you need more message brokers, you should have a look at \u003ca href=\"https://github.com/php-enqueue/messenger-adapter\"\u003eEnqueue's transport\u003c/a\u003e\nwhich supports things like Kafka, Amazon SQS or Google Pub/Sub.\u003c/p\u003e\n\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eA transport is registered using a \"DSN\", which is a string that represents the\nconnection credentials and configuration. By default, when you've installed\nthe messenger component, the following configuration should have been created:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n transports:\n amqp: \"%env(MESSENGER_TRANSPORT_DSN)%\"\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:transport name=\"amqp\" dsn=\"%env(MESSENGER_TRANSPORT_DSN)%\" /\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'transports' =\u0026gt; [\n 'amqp' =\u0026gt; '%env(MESSENGER_TRANSPORT_DSN)%',\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cdiv class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# .env\n###\u0026gt; symfony/messenger ###\nMESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages\n###\u0026lt; symfony/messenger ###\"\u003e\u003cpre\u003e\u003cspan class=\"pl-c\"\u003e\u003cspan class=\"pl-c\"\u003e#\u003c/span\u003e .env\u003c/span\u003e\n\u003cspan class=\"pl-c\"\u003e\u003cspan class=\"pl-c\"\u003e#\u003c/span\u003e##\u0026gt; symfony/messenger ###\u003c/span\u003e\nMESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages\n\u003cspan class=\"pl-c\"\u003e\u003cspan class=\"pl-c\"\u003e#\u003c/span\u003e##\u0026lt; symfony/messenger ###\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThis is enough to allow you to route your message to the \u003ccode\u003eamqp\u003c/code\u003e transport.\nThis will also configure the following services for you:\u003c/p\u003e\n\u003col dir=\"auto\"\u003e\n\u003cli\u003eA \u003ccode\u003emessenger.sender.amqp\u003c/code\u003e sender to be used when routing messages;\u003c/li\u003e\n\u003cli\u003eA \u003ccode\u003emessenger.receiver.amqp\u003c/code\u003e receiver to be used when consuming messages.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIn order to use Symfony's built-in AMQP transport, you will need the Serializer\nComponent. Ensure that it is installed with:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ composer require symfony/serializer-pack\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-routing\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRouting\u003c/h3\u003e\u003ca id=\"user-content-routing\" class=\"anchor\" aria-label=\"Permalink: Routing\" href=\"#routing\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eInstead of calling a handler, you have the option to route your message(s) to a\nsender. Part of a transport, it is responsible for sending your message somewhere.\nYou can configure which message is routed to which sender with the following\nconfiguration:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n routing:\n 'My\\Message\\Message': amqp # The name of the defined transport\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:routing message-class=\"My\\Message\\Message\"\u0026gt;\n \u0026lt;framework:sender service=\"amqp\" /\u0026gt;\n \u0026lt;/framework:routing\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'routing' =\u0026gt; [\n 'My\\Message\\Message' =\u0026gt; 'amqp',\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eSuch configuration would only route the \u003ccode\u003eMy\\Message\\Message\u003c/code\u003e message to be\nasynchronous, the rest of the messages would still be directly handled.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eYou can route all classes of messages to the same sender using an asterisk\ninstead of a class name:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n routing:\n 'My\\Message\\MessageAboutDoingOperationalWork': another_transport\n '*': amqp\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:routing message-class=\"My\\Message\\Message\"\u0026gt;\n \u0026lt;framework:sender service=\"another_transport\" /\u0026gt;\n \u0026lt;/framework:routing\u0026gt;\n \u0026lt;framework:routing message-class=\"*\"\u0026gt;\n \u0026lt;framework:sender service=\"amqp\" /\u0026gt;\n \u0026lt;/framework:routing\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'routing' =\u0026gt; [\n 'My\\Message\\Message' =\u0026gt; 'another_transport',\n '*' =\u0026gt; 'amqp',\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eA class of messages can also be routed to multiple senders by specifying a list:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n routing:\n 'My\\Message\\ToBeSentToTwoSenders': [amqp, audit]\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:routing message-class=\"My\\Message\\ToBeSentToTwoSenders\"\u0026gt;\n \u0026lt;framework:sender service=\"amqp\" /\u0026gt;\n \u0026lt;framework:sender service=\"audit\" /\u0026gt;\n \u0026lt;/framework:routing\u0026gt;\n 8000 \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'routing' =\u0026gt; [\n 'My\\Message\\ToBeSentToTwoSenders' =\u0026gt; ['amqp', 'audit'],\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eBy specifying the \u003ccode\u003esend_and_handle\u003c/code\u003e option, you can also route a class of messages to a sender\nwhile still having them passed to their respective handler:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n routing:\n 'My\\Message\\ThatIsGoingToBeSentAndHandledLocally':\n senders: [amqp]\n send_and_handle: true\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:routing message-class=\"My\\Message\\ThatIsGoingToBeSentAndHandledLocally\" send-and-handle=\"true\"\u0026gt;\n \u0026lt;framework:sender service=\"amqp\" /\u0026gt;\n \u0026lt;/framework:routing\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'routing' =\u0026gt; [\n 'My\\Message\\ThatIsGoingToBeSentAndHandledLocally' =\u0026gt; [\n 'senders' =\u0026gt; ['amqp'],\n 'send_and_handle' =\u0026gt; true,\n ],\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-consuming-messages\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsuming Messages\u003c/h3\u003e\u003ca id=\"user-content-consuming-messages\" class=\"anchor\" aria-label=\"Permalink: Consuming Messages\" href=\"#consuming-messages\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eOnce your messages have been routed, you will like to consume your messages in most\nof the cases. To do so, you can use the \u003ccode\u003emessenger:consume-messages\u003c/code\u003e command\nlike this:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ bin/console messenger:consume-messages amqp\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe first argument is the receiver's service name. It might have been created by\nyour \u003ccode\u003etransports\u003c/code\u003e configuration or it can be your own receiver.\u003c/p\u003e\n\u003ca name=\"user-content-middleware\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eMiddleware\u003c/h3\u003e\u003ca id=\"user-content-middleware\" class=\"anchor\" aria-label=\"Permalink: Middleware\" href=\"#middleware\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eWhat happens when you dispatch a message to a message bus(es) depends on its\ncollection of middleware (and their order). By default, the middleware configured\nfor each bus looks like this:\u003c/p\u003e\n\u003col dir=\"auto\"\u003e\n\u003cli\u003e\u003ccode\u003elogging\u003c/code\u003e middleware. Responsible for logging the beginning and the end of the\nmessage within the bus;\u003c/li\u003e\n\u003cli\u003e_Your own collection of \u003ca href=\"#middleware\"\u003emiddleware\u003c/a\u003e;\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003eroute_messages\u003c/code\u003e middleware. Will route the messages you configured to their\ncorresponding sender and stop the middleware chain;\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003ecall_message_handler\u003c/code\u003e middleware. Will call the message handler(s) for the\ngiven message.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eThese middleware names are actually shortcuts working by convention.\nThe real service ids are prefixed with the \u003ccode\u003emessenger.middleware.\u003c/code\u003e namespace.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-disabling-default-middleware\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eDisabling default Middleware\u003c/h4\u003e\u003ca id=\"user-content-disabling-default-middleware\" class=\"anchor\" aria-label=\"Permalink: Disabling default Middleware\" href=\"#disabling-default-middleware\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eIf you don't want the default collection of middleware to be present on your bus,\nyou can disable them like this:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n buses:\n messenger.bus.default:\n default_middleware: false\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:bus name=\"messenger.bus.default\" default-middleware=\"false\" /\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'buses' =\u0026gt; [\n 'messenger.bus.default' =\u0026gt; [\n 'default_middleware' =\u0026gt; false,\n ],\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-adding-your-own-middleware\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eAdding your own Middleware\u003c/h4\u003e\u003ca id=\"user-content-adding-your-own-middleware\" class=\"anchor\" aria-label=\"Permalink: Adding your own Middleware\" href=\"#adding-your-own-middleware\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eAs described in the component documentation, you can add your own middleware\nwithin the buses to add some extra capabilities like this:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n buses:\n messenger.bus.default:\n middleware:\n - 'App\\Middleware\\MyMiddleware'\n - 'App\\Middleware\\AnotherMiddleware'\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:bus name=\"messenger.bus.default\"\u0026gt;\n \u0026lt;framework:middleware id=\"App\\Middleware\\MyMiddleware\" /\u0026gt;\n \u0026lt;framework:middleware id=\"App\\Middleware\\AnotherMiddleware\" /\u0026gt;\n \u0026lt;/framework:bus\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'buses' =\u0026gt; [\n 'messenger.bus.default' =\u0026gt; [\n 'middleware' =\u0026gt; [\n 'App\\Middleware\\MyMiddleware',\n 'App\\Middleware\\AnotherMiddleware',\n ],\n ],\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eNote that if the service is abstract, a different instance of the service will\nbe created per bus.\u003c/p\u003e\n\u003ca name=\"user-content-using-middleware-factories\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eUsing Middleware Factories\u003c/h4\u003e\u003ca id=\"user-content-using-middleware-factories\" class=\"anchor\" aria-label=\"Permalink: Using Middleware Factories\" href=\"#using-middleware-factories\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eSome third-party bundles and libraries provide configurable middleware via\nfactories. Defining such requires a two-step configuration based on Symfony's\n\u003ca href=\"#id15\"\u003e\u003cspan id=\"user-content-id16\"\u003e:doc:`dependency injection \u0026lt;/service_container\u0026gt;`\u003c/span\u003e\u003c/a\u003e features:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/services.yaml\n services:\n\n # Step 1: a factory class is registered as a service with the required\n # dependencies to instantiate a middleware\n doctrine.orm.messenger.middleware_factory.transaction:\n class: Symfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddlewareFactory\n arguments: ['@doctrine']\n\n # Step 2: an abstract definition that will call the factory with default\n # arguments or the ones provided in the middleware config\n messenger.middleware.doctrine_transaction:\n class: Symfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddleware\n factory: 'doctrine.orm.messenger.middleware_factory.transaction:createMiddleware'\n abstract: true\n # the default arguments to use when none provided from config. Example:\n # middleware:\n # - doctrine_transaction: ~\n arguments: ['default']\n\n .. code-block:: xml\n\n \u0026lt;!-- config/services.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\"\u0026gt;\n\n \u0026lt;services\u0026gt;\n \u0026lt;!-- Step 1: a factory class is registered as a service with the required\n dependencies to instantiate a middleware --\u0026gt;\n \u0026lt;service id=\"doctrine.orm.messenger.middleware_factory.transaction\"\n class=\"Symfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddlewareFactory\"\u0026gt;\n\n \u0026lt;argument type=\"service\" id=\"doctrine\" /\u0026gt;\n \u0026lt;/service\u0026gt;\n\n \u0026lt;!-- Step 2: an abstract definition that will call the factory with default\n arguments or the ones provided in the middleware config --\u0026gt;\n \u0026lt;service id=\"messenger.middleware.doctrine_transaction\"\n class=\"Symfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddleware\"\n abstract=\"true\"\u0026gt;\n\n \u0026lt;factory service=\"doctrine.orm.messenger.middleware_factory.transaction\"\n method=\"createMiddleware\" /\u0026gt;\n \u0026lt;argument\u0026gt;default\u0026lt;/argument\u0026gt;\n \u0026lt;/service\u0026gt;\n \u0026lt;/services\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/services.php\n use Symfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddleware;\n use Symfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddlewareFactory;\n use Symfony\\Component\\DependencyInjection\\Reference;\n\n // Step 1: a factory class is registered as a service with the required\n // dependencies to instantiate a middleware\n $container\n -\u0026gt;register('doctrine.orm.messenger.middleware_factory.transaction', DoctrineTransactionMiddlewareFactory::class)\n -\u0026gt;setArguments([new Reference('doctrine')]);\n\n // Step 2: an abstract definition that will call the factory with default\n // arguments or the ones provided in the middleware config\n $container-\u0026gt;register('messenger.middleware.doctrine_transaction', DoctrineTransactionMiddleware::class)\n -\u0026gt;setFactory([\n new Reference('doctrine.orm.messenger.middleware_factory.transaction'),\n 'createMiddleware'\n ])\n -\u0026gt;setAbstract(true)\n -\u0026gt;setArguments(['default']);\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe \"default\" value in this example is the name of the entity manager to use,\nwhich is the argument expected by the\n\u003ccode\u003eSymfony\\Bridge\\Doctrine\\Messenger\\DoctrineTransactionMiddlewareFactory::createMiddleware\u003c/code\u003e method.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eThen you can reference and configure the\n\u003ccode\u003emessenger.middleware.doctrine_transaction\u003c/code\u003e service as a middleware:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n buses:\n command_bus:\n middleware:\n # Using defaults\n - doctrine_transaction\n # Using another entity manager\n - doctrine_transaction: ['custom']\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:bus name=\"command_bus\"\u0026gt;\n \u0026lt;!-- Using defaults --\u0026gt;\n \u0026lt;framework:middleware id=\"doctrine_transaction\" /\u0026gt;\n \u0026lt;!-- Using another entity manager --\u0026gt;\n \u0026lt;framework:middleware id=\"doctrine_transaction\"\u0026gt;\n \u0026lt;framework:argument\u0026gt;custom\u0026lt;/framework:argument\u0026gt;\n \u0026lt;/framework:middleware\u0026gt;\n \u0026lt;/framework:bus\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'buses' =\u0026gt; [\n 'command_bus' =\u0026gt; [\n 'middleware' =\u0026gt; [\n // Using defaults\n 'doctrine_transaction',\n // Using another entity manager\n ['id' =\u0026gt; 'doctrine_transaction', 'arguments' =\u0026gt; ['custom']],\n ],\n ],\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eMiddleware factories only allow scalar and array arguments in config (no\nreferences to other services). For most advanced use-cases, register a\nconcrete definition of the middleware manually and use its id.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eThe \u003ccode\u003emessenger.middleware.doctrine_transaction\u003c/code\u003e middleware is a built-in\nmiddleware wired automatically when the DoctrineBundle and the Messenger\ncomponent are installed and enabled.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-your-own-transport\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eYour own Transport\u003c/h3\u003e\u003ca id=\"user-content-your-own-transport\" class=\"anchor\" aria-label=\"Permalink: Your own Transport\" href=\"#your-own-transport\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eOnce you have written your transport's sender and receiver, you can register your\ntransport factory to be able to use it via a DSN in the Symfony application.\u003c/p\u003e\n\u003ca name=\"user-content-create-your-transport-factory\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eCreate your Transport Factory\u003c/h4\u003e\u003ca id=\"user-content-create-your-transport-factory\" class=\"anchor\" aria-label=\"Permalink: Create your Transport Factory\" href=\"#create-your-transport-factory\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eYou need to give FrameworkBundle the opportunity to create your transport from a\nDSN. You will need a transport factory:\u003c/p\u003e\n\u003cpre\u003euse Symfony\\Component\\Messenger\\Transport\\TransportFactoryInterface;\nuse Symfony\\Component\\Messenger\\Transport\\TransportInterface;\nuse Symfony\\Component\\Messenger\\Transport\\ReceiverInterface;\nuse Symfony\\Component\\Messenger\\Transport\\SenderInterface;\n\nclass YourTransportFactory implements TransportFactoryInterface\n{\n public function createTransport(string $dsn, array $options): TransportInterface\n {\n return new YourTransport(/* ... */);\n }\n\n public function supports(string $dsn, array $options): bool\n {\n return 0 === strpos($dsn, 'my-transport://');\n }\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe transport object needs to implement the \u003ccode\u003eTransportInterface\u003c/code\u003e (which simply combines\nthe \u003ccode\u003eSenderInterface\u003c/code\u003e and \u003ccode\u003eReceiverInterface\u003c/code\u003e). It will look like this:\u003c/p\u003e\n\u003cpre\u003eclass YourTransport implements TransportInterface\n{\n public function send($message): void\n {\n // ...\n }\n\n public function receive(callable $handler): void\n {\n // ...\n }\n\n public function stop(): void\n {\n // ...\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-register-your-factory\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRegister your Factory\u003c/h4\u003e\u003ca id=\"user-content-register-your-factory\" class=\"anchor\" aria-label=\"Permalink: Register your Factory\" href=\"#register-your-factory\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/services.yaml\n services:\n Your\\Transport\\YourTransportFactory:\n tags: [messenger.transport_factory]\n\n .. code-block:: xml\n\n \u0026lt;!-- config/services.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\"\u0026gt;\n\n \u0026lt;services\u0026gt;\n \u0026lt;service id=\"Your\\Transport\\YourTransportFactory\"\u0026gt;\n \u0026lt;tag name=\"messenger.transport_factory\" /\u0026gt;\n \u0026lt;/service\u0026gt;\n \u0026lt;/services\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/services.php\n use Your\\Transport\\YourTransportFactory;\n\n $container-\u0026gt;register(YourTransportFactory::class)\n -\u0026gt;setTags(['messenger.transport_factory']);\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-use-your-transport\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eUse your Transport\u003c/h4\u003e\u003ca id=\"user-content-use-your-transport\" class=\"anchor\" aria-label=\"Permalink: Use your Transport\" href=\"#use-your-transport\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eWithin the \u003ccode\u003eframework.messenger.transports.*\u003c/code\u003e configuration, create your\nnamed transport using your own DSN:\u003c/p\u003e\n\u003cpre\u003e.. configuration-block::\n\n .. code-block:: yaml\n\n # config/packages/messenger.yaml\n framework:\n messenger:\n transports:\n yours: 'my-transport://...'\n\n .. code-block:: xml\n\n \u0026lt;!-- config/packages/messenger.xml --\u0026gt;\n \u0026lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?\u0026gt;\n \u0026lt;container xmlns=\"http://symfony.com/schema/dic/services\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xmlns:framework=\"http://symfony.com/schema/dic/symfony\"\n xsi:schemaLocation=\"http://symfony.com/schema/dic/services\n http://symfony.com/schema/dic/services/services-1.0.xsd\n http://symfony.com/schema/dic/symfony\n http://symfony.com/schema/dic/symfony/symfony-1.0.xsd\"\u0026gt;\n\n \u0026lt;framework:config\u0026gt;\n \u0026lt;framework:messenger\u0026gt;\n \u0026lt;framework:transport name=\"yours\" dsn=\"my-transport://...\" /\u0026gt;\n \u0026lt;/framework:messenger\u0026gt;\n \u0026lt;/framework:config\u0026gt;\n \u0026lt;/container\u0026gt;\n\n .. code-block:: php\n\n // config/packages/messenger.php\n $container-\u0026gt;loadFromExtension('framework', [\n 'messenger' =\u0026gt; [\n 'transports' =\u0026gt; [\n 'yours' =\u0026gt; 'my-transport://...',\n ],\n ],\n ]);\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eIn addition of being able to route your messages to the \u003ccode\u003eyours\u003c/code\u003e sender, this\nwill give you access to the following services:\u003c/p\u003e\n\u003col dir=\"auto\"\u003e\n\u003cli\u003e\u003ccode\u003emessenger.sender.yours\u003c/code\u003e: the sender;\u003c/li\u003e\n\u003cli\u003e\u003ccode\u003emessenger.receiver.yours\u003c/code\u003e: the receiver.\u003c/li\u003e\n\u003c/ol\u003e\n\u003ca name=\"user-content-learn-more\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" d 32F6 ir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eLearn more\u003c/h3\u003e\u003ca id=\"user-content-learn-more\" class=\"anchor\" aria-label=\"Permalink: Learn more\" href=\"#learn-more\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cpre\u003e.. toctree::\n :maxdepth: 1\n :glob:\n\n /messenger/*\n\n\u003c/pre\u003e\n\n\u003c/article\u003e","renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":2,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":"/symfony/.github/blob/6f2ca452c856184a28812bb364b4e34ed50309da/FUNDING.yml","showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/symfony/symfony-docs/branches":{"post":"pSj0j6nFCttNvwqA8s8xBSGo7aQA50wHkqBd8dz4CLUWKVl84pLQhmSqdjXb8CmFpx-it6LCFLvjLOaK7jxN_w"},"/repos/preferences":{"post":"QG-62N8_CBiV9wCyT0U8YxgEeq_kAv90GMlADRshY3ch1NEmcvSQY7VVqibNmP9pXokY4zpTHC3pPEIp529axg"}}},"title":"symfony-docs/messenger.rst at 4.1 · symfony/symfony-docs","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-b84e9496fc59.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0