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        | https://github.com/symfony/symfony-docs/pull/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
-------

c965e4e844 [Messenger] Added support for `from_transport` attribute on `messenger.message_handler` tag
This commit is contained in:
Fabien Potencier 2019-09-25 20:39:14 +02:00
commit e2e73eff1d
3 changed files with 24 additions and 0 deletions

View File

@ -9,6 +9,7 @@ CHANGELOG
* Added support for auto trimming of Redis streams.
* `InMemoryTransport` handle acknowledged and rejected messages.
* Made all dispatched worker event classes final.
* Added support for `from_transport` attribute on `messenger.message_handler` tag.
4.3.0
-----

View File

@ -109,6 +109,10 @@ class MessengerPass implements CompilerPassInterface
$options = ['method' => $options];
}
if (!isset($options['from_transport']) && isset($tag['from_transport'])) {
$options['from_transport'] = $tag['from_transport'];
}
$priority = $tag['priority'] ?? $options['priority'] ?? 0;
$method = $options['method'] ?? '__invoke';

View File

@ -78,6 +78,25 @@ class MessengerPassTest extends TestCase
);
}
public function testFromTransportViaTagAttribute()
{
$container = $this->getContainerBuilder($busId = 'message_bus');
$container
->register(DummyHandler::class, DummyHandler::class)
->addTag('messenger.message_handler', ['from_transport' => 'async'])
;
(new MessengerPass())->process($container);
$handlersLocatorDefinition = $container->getDefinition($busId.'.messenger.handlers_locator');
$this->assertSame(HandlersLocator::class, $handlersLocatorDefinition->getClass());
$handlerDescriptionMapping = $handlersLocatorDefinition->getArgument(0);
$this->assertCount(1, $handlerDescriptionMapping);
$this->assertHandlerDescriptor($container, $handlerDescriptionMapping, DummyMessage::class, [DummyHandler::class], [['from_transport' => 'async']]);
}
public function testProcessHandlersByBus()
{
$container = $this->getContainerBuilder($commandBusId = 'command_bus');