Skip to content

Commit e2e73ef

Browse files
committed
feature #33317 [Messenger] Added support for from_transport attribute on messenger.message_handler tag (ruudk)
This PR was squashed before being merged into the 4.4 branch (closes #33317). Discussion ---------- [Messenger] Added support for `from_transport` attribute on `messenger.message_handler` tag | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #33306 | License | MIT | Doc PR | symfony/symfony-docs#12231 Right now, it's only possible to have dynamic `from_transport` when using `MessageSubscriberInterface`. Things like `priority` and `bus` can already be added as attributes on the messenger.message_handler` tag. With this PR it now also supports `from_transport`. Commits ------- c965e4e [Messenger] Added support for `from_transport` attribute on `messenger.message_handler` tag
2 parents a0bbae7 + c965e4e commit e2e73ef

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Symfony/Component/Messenger/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* Added support for auto trimming of Redis streams.
1010
* `InMemoryTransport` handle acknowledged and rejected messages.
1111
* Made all dispatched worker event classes final.
12+
* Added support for `from_transport` attribute on `messenger.message_handler` tag.
1213

1314
4.3.0
1415
-----

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
109109
$options = ['method' => $options];
110110
}
111111

112+
if (!isset($options['from_transport']) && isset($tag['from_transport'])) {
113+
$options['from_transport'] = $tag['from_transport'];
114+
}
115+
112116
$priority = $tag['priority'] ?? $options['priority'] ?? 0;
113117
$method = $options['method'] ?? '__invoke';
114118

src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ public function testProcess()
7878
);
7979
}
8080

81+
public function testFromTransportViaTagAttribute()
82+
{
83+
$container = $this->getContainerBuilder($busId = 'message_bus');
84+
$container
85+
->register(DummyHandler::class, DummyHandler::class)
86+
->addTag('messenger.message_handler', ['from_transport' => 'async'])
87+
;
88+
89+
(new MessengerPass())->process($container);
90+
91+
$handlersLocatorDefinition = $container->getDefinition($busId.'.messenger.handlers_locator');
92+
$this->assertSame(HandlersLocator::class, $handlersLocatorDefinition->getClass());
93+
94+
$handlerDescriptionMapping = $handlersLocatorDefinition->getArgument(0);
95+
$this->assertCount(1, $handlerDescriptionMapping);
96+
97+
$this->assertHandlerDescriptor($container, $handlerDescriptionMapping, DummyMessage::class, [DummyHandler::class], [['from_transport' => 'async']]);
98+
}
99+
81100
public function testProcessHandlersByBus()
82101
{
83102
$container = $this->getContainerBuilder($commandBusId = 'command_bus');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy