Skip to content

Commit 0091864

Browse files
committed
bug symfony#37364 [Messenger] fixed queue_name option on amazon sqs connection (ck-developer)
This PR was merged into the 5.1 branch. Discussion ---------- [Messenger] fixed queue_name option on amazon sqs connection | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#37293 | License | MIT Commits ------- a6cb24d [Messenger] fixed queue_name option amazon sqs connection
2 parents 71b65d4 + a6cb24d commit 0091864

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ public function testFromDsnWithQueryOptions()
124124
);
125125
}
126126

127+
public function testFromDsnWithQueueNameOption()
128+
{
129+
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
130+
131+
$this->assertEquals(
132+
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
133+
Connection::fromDsn('sqs://default', ['queue_name' => 'queue'], $httpClient)
134+
);
135+
136+
$this->assertEquals(
137+
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
138+
Connection::fromDsn('sqs://default/queue', ['queue_name' => 'queue_ignored'], $httpClient)
139+
);
140+
}
141+
127142
public function testKeepGettingPendingMessages()
128143
{
129144
$client = $this->createMock(SqsClient::class);

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
101101
'poll_timeout' => $options['poll_timeout'],
102102
'visibility_timeout' => $options['visibility_timeout'],
103103
'auto_setup' => (bool) $options['auto_setup'],
104+
'queue_name' => (string) $options['queue_name'],
104105
];
105106

106107
$clientConfiguration = [
@@ -119,8 +120,8 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
119120
}
120121

121122
$parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/'));
122-
if (\count($parsedPath) > 0) {
123-
$configuration['queue_name'] = end($parsedPath);
123+
if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath))) {
124+
$configuration['queue_name'] = $queueName;
124125
}
125126
$configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : null;
126127

0 commit comments

Comments
 (0)