Skip to content

Commit 04c7ccf

Browse files
bug #51508 [Messenger] Fix routing to multiple fallback transports (valtzu)
This PR was merged into the 6.3 branch. Discussion ---------- [Messenger] Fix routing to multiple fallback transports | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT The change made in #48121 means that it's not possible to route into multiple transport as fallback like ```yaml framework: messenger: routing: My\Message\*: [async, audit] ``` F.e. the message `My\Message\ToBeSentToTwoSenders` would only reach `async`. The comment in the code mentions > if other senders already matched **with previous types**, skip the senders bound to the fallback While in reality how it works is > if other senders already matched, skip the senders bound to the fallback After the changes in this MR it works as mentioned in the original comment, meaning it does not skip for the same type, but routes to all transports for that type. --- This is not a BC break because anyone who has more than one transport in a wildcard rule has never received anything matching the wildcard on other than the 1st transport – so only if you had a misconfiguration in the first place you're affected. Commits ------- 76f2433 Fix routing to multiple fallback transports
2 parents b9be69f + 76f2433 commit 04c7ccf

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Sender/SendersLocatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,19 @@ public function testSendersMapWithFallback()
5656
{
5757
$firstSender = $this->createMock(SenderInterface::class);
5858
$secondSender = $this->createMock(SenderInterface::class);
59+
$thirdSender = $this->createMock(SenderInterface::class);
5960
$sendersLocator = $this->createContainer([
6061
'first' => $firstSender,
6162
'second' => $secondSender,
63+
'third' => $thirdSender,
6264
]);
6365
$locator = new SendersLocator([
6466
DummyMessage::class => ['first'],
65-
'*' => ['second'],
67+
'*' => ['second', 'third'],
6668
], $sendersLocator);
6769

6870
$this->assertSame(['first' => $firstSender], iterator_to_array($locator->getSenders(new Envelope(new DummyMessage('a')))), 'Unexpected senders for configured message');
69-
$this->assertSame(['second' => $secondSender], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))), 'Unexpected senders for unconfigured message');
71+
$this->assertSame(['second' => $secondSender, 'third' => $thirdSender], iterator_to_array($locator->getSenders(new Envelope(new SecondMessage()))), 'Unexpected senders for unconfigured message');
7072
}
7173

7274
private function createContainer(array $senders): ContainerInterface

src/Symfony/Component/Messenger/Transport/Sender/SendersLocator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public function getSenders(Envelope $envelope): iterable
5050
$seen = [];
5151

5252
foreach (HandlersLocator::listTypes($envelope) as $type) {
53-
foreach ($this->sendersMap[$type] ?? [] as $senderAlias) {
54-
if (str_ends_with($type, '*') && $seen) {
55-
// the '*' acts as a fallback, if other senders already matched
56-
// with previous types, skip the senders bound to the fallback
57-
continue;
58-
}
53+
if (str_ends_with($type, '*') && $seen) {
54+
// the '*' acts as a fallback, if other senders already matched
55+
// with previous types, skip the senders bound to the fallback
56+
continue;
57+
}
5958

59+
foreach ($this->sendersMap[$type] ?? [] as $senderAlias) {
6060
if (!\in_array($senderAlias, $seen, true)) {
6161
$seen[] = $senderAlias;
6262

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