You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #29010 [Messenger] make senders and handlers subscribing to parent interfaces receive *all* matching messages, wildcard included (nicolas-grekas)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Messenger] make senders and handlers subscribing to parent interfaces receive *all* matching messages, wildcard included
| Q | A
| ------------- | ---
| Branch? | 4.2
| Bug fix? | no
| New feature? | yes
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
~Embeds #29006 for now.~
From the CHANGELOG:
* senders and handlers subscribing to parent interfaces now receive *all* matching messages, wildcard included
* `HandlerLocatorInterface::resolve()` has been removed, use `HandlersLocator::getHandlers()` instead
* `SenderLocatorInterface::getSenderForMessage()` has been removed, use `SendersLocator::getSenders()` instead
* The `ChainHandler` and `ChainSender` classes have been removed
* The `ContainerHandlerLocator`, `AbstractHandlerLocator`, `SenderLocator` and `AbstractSenderLocator` classes have been removed
The new `HandlersLocatorInterface` and `SendersLocatorInterface` interfaces return **`iterable`** of corresponding handlers/senders. This allows simplifying a lot the DI configuration and standalone usage.
Inheritance-based configuration is now stable: when a sender or a handler is bound to `SomeMessageInterface`, it will always get all messages of that kind. This fixes the unstable nature of the previous logic, where only the first matching type bound to a message would match, making routing/handling unpredictable (note that the new behavior is also how Laravel does it.)
Some cleanups found meanwhile:
* the `messenger.sender` tag was useless, it's removed
* the reponsibility of the "send-and-handle" decision has been moved to the locator, where it belongs
* thanks to type+argument autowiring aliases, we don't need to force defining a default bus - gaining nice errors when a named argument has a typo
* some services have been renamed to make them more conventional
As far as priorities are concerned, the priority number applies in the scope of the type bound to it: senders/handlers that are bound to more specific types are always called before less specific ones, no matter the defined priority.
Commits
-------
1e7af4d [Messenger] make senders and handlers subscribing to parent interfaces receive *all* matching messages, wildcard included
if (!interface_exists(MessageBusInterface::class)) {
1494
-
thrownewLogicException('Messenger support cannot be enabled as the Messenger component is not installed.');
1495
+
thrownewLogicException('Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger".');
1495
1496
}
1496
1497
1497
1498
$loader->load('messenger.xml');
@@ -1502,7 +1503,7 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
1502
1503
} else {
1503
1504
if ('messenger.transport.symfony_serializer' === $config['serializer']['id']) {
1504
1505
if (!$this->isConfigEnabled($container, $serializerConfig)) {
1505
-
thrownewLogicException('The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack".');
1506
+
thrownewLogicException('The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".');
@@ -1517,17 +1518,13 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
1517
1518
}
1518
1519
}
1519
1520
1520
-
if (null === $config['default_bus']) {
1521
-
if (\count($config['buses']) > 1) {
1522
-
thrownewLogicException(sprintf('You need to define a default bus with the "default_bus" configuration. Possible values: %s', implode(', ', array_keys($config['buses']))));
1523
-
}
1524
-
1521
+
if (null === $config['default_bus'] && 1 === \count($config['buses'])) {
if (0 === strpos($transport['dsn'], 'amqp://') && !$container->hasDefinition('messenger.transport.amqp.factory')) {
1572
-
thrownewLogicException('The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack".');
1565
+
thrownewLogicException('The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enabling it or running "composer require symfony/serializer-pack".');
if ('*' !== $message && !class_exists($message) && !interface_exists($message, false)) {
1589
-
thrownewLogicException(sprintf('Messenger routing configuration contains a mistake: message "%s" does not exist. It needs to match an existing class or interface.', $message));
1581
+
thrownewLogicException(sprintf('Invalid Messenger routing configuration: class or interface "%s" not found.', $message));
1590
1582
}
1583
+
$senders = array_map(function ($sender) use ($senderAliases) {
* @expectedExceptionMessage The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enable it or install it by running "composer require symfony/serializer-pack".
578
+
* @expectedExceptionMessage The default Messenger serializer cannot be enabled as the Serializer support is not available. Try enabling it or running "composer require symfony/serializer-pack".
* @expectedExceptionMessage The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enable it or install it by running "composer require symfony/serializer-pack".
587
+
* @expectedExceptionMessage The default AMQP transport is not available. Make sure you have installed and enabled the Serializer component. Try enabling it or running "composer require symfony/serializer-pack".
0 commit comments