Skip to content

[Messenger] #44254 Changing queue name precedence #44291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 5.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixing queue_name precedence: config -> DSN -> default
  • Loading branch information
Alexey Deriyenko committed Nov 26, 2021
commit 2d0c19961b8dbb7ddd190a9c6ac5d09ecedc411d
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,24 @@ public function testDsnPrecedence()
{
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)),
new Connection(['queue_name' => 'queue_options'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)),
Connection::fromDsn('sqs://key_dsn:secret_dsn@default/queue_dsn?region=us-east-2', ['region' => 'eu-west-3', 'queue_name' => 'queue_options', 'access_key' => 'key_option', 'secret_key' => 'secret_option'], $httpClient)
);
}

public function testQueueNameDefault()
{
$httpClient = $this->createMock(HttpClientInterface::class);
$this->assertEquals(
new Connection(['queue_name' => 'messages'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)),
Connection::fromDsn(
'sqs://key_dsn:secret_dsn@default/?region=us-east-2',
['region' => 'eu-west-3', 'access_key' => 'key_option', 'secret_key' => 'secret_option'],
$httpClient
)
);
}

public function testFromDsnWithRegion()
{
$httpClient = $this->createMock(HttpClientInterface::class);
Expand Down Expand Up @@ -165,7 +178,7 @@ public function testFromDsnWithQueueNameOption()

$this->assertEquals(
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
Connection::fromDsn('sqs://default/queue', ['queue_name' => 'queue_ignored'], $httpClient)
Connection::fromDsn('sqs://default/queue_ignored', ['queue_name' => 'queue'], $httpClient)
);
}

Expand Down Expand Up @@ -342,7 +355,8 @@ public function testLoggerWithDebugOption()

private function getMockedQueueUrlResponse(): MockResponse
{
return new MockResponse(<<<XML
return new MockResponse(
<<<XML
<GetQueueUrlResponse>
<GetQueueUrlResult>
<QueueUrl>https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue</QueueUrl>
Expand All @@ -357,7 +371,8 @@ private function getMockedQueueUrlResponse(): MockResponse

private function getMockedReceiveMessageResponse(): MockResponse
{
return new MockResponse(<<<XML
return new MockResponse(
<<<XML
<ReceiveMessageResponse>
<ReceiveMessageResult>
<Message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s].', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS))));
}

$parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/'));
if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath)) && empty($options['queue_name'])) {
$options['queue_name'] = $queueName;
}

$options = $query + $options + self::DEFAULT_OPTIONS;
$configuration = [
'buffer_size' => (int) $options['buffer_size'],
Expand Down Expand Up @@ -157,10 +162,6 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
$clientConfiguration['endpoint'] = $options['endpoint'];
}

$parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/'));
if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath))) {
$configuration['queue_name'] = $queueName;
}
$configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : $options['account'] ?? self::DEFAULT_OPTIONS['account'];

// When the DNS looks like a QueueUrl, we can directly inject it in the connection
Expand Down
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