8000 bug #36449 [Messenger] Make sure redis transports are initialized cor… · symfony/symfony@efb0dee · GitHub
[go: up one dir, main page]

Skip to content

Commit efb0dee

Browse files
committed
bug #36449 [Messenger] Make sure redis transports are initialized correctly (Seldaek)
This PR was squashed before being merged into the 4.4 branch (closes #36449). Discussion ---------- [Messenger] Make sure redis transports are initialized correctly | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT Took me a while to figure out why my messages were dispatched/handled twice.. Turns out I had two messenger transports using the same dsn and the parsing was broken so they ended up both polling from a `""` stream, which caused them to both handle the messages (I think). Below my config, note the trailing slash in the dsn was the root cause of the issue, but I don't think it's that unreasonable. ``` .env: MESSENGER_TRANSPORT_DSN=redis://localhost:6379/?dbindex=3 messenger.yml: async_urgent: dsn: '%env(MESSENGER_TRANSPORT_DSN)%' options: group: async_urgent stream: messages_urgent async: dsn: '%env(MESSENGER_TRANSPORT_DSN)%' options: group: async stream: messages ``` Commits ------- 68b3b89 [Messenger] Make sure redis transports are initialized correctly
2 parents b3333e5 + 68b3b89 commit efb0dee

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public function testFromDsnWithOptions()
6262
);
6363
}
6464

65+
public function testFromDsnWithOptionsAndTrailingSlash()
66+
{
67+
$this->assertEquals(
68+
Connection::fromDsn('redis://localhost/', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2]),
69+
Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0')
70+
);
71+
}
72+
6573
public function testFromDsnWithQueryOptions()
6674
{
6775
$this->assertEquals(

src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public function __construct(array $configuration, array $connectionCredentials =
6363
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
6464
}
6565

66+
foreach (['stream', 'group', 'consumer'] as $key) {
67+
if (isset($configuration[$key]) && '' === $configuration[$key]) {
68+
throw new InvalidArgumentException(sprintf('"%s" should be configured, got an empty string.', $key));
69+
}
70+
}
71+
6672
$this->stream = $configuration['stream'] ?? self::DEFAULT_OPTIONS['stream'];
6773
$this->group = $configuration['group'] ?? self::DEFAULT_OPTIONS['group'];
6874
$this->consumer = $configuration['consumer'] ?? self::DEFAULT_OPTIONS['consumer'];
@@ -77,7 +83,7 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
7783
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
7884
}
7985

80-
$pathParts = explode('/', $parsedUrl['path'] ?? '');
86+
$pathParts = explode('/', rtrim($parsedUrl['path'] ?? '', '/'));
8187

8288
$stream = $pathParts[1] ?? $redisOptions['stream'] ?? null;
8389
$group = $pathParts[2] ?? $redisOptions['group'] ?? null;

0 commit comments

Comments
 (0)
0