Skip to content

Commit 2555ac1

Browse files
feat(snsqs): allow client http configuration for sns and sqs
This changes allow to set in the AWS Sdk client the http configurations: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_configuration.html#config-http This will make possible to define custom `connect_timeout` and `timeout` to fail fast when the network is not relaible. Reported on #1213
1 parent bb4a036 commit 2555ac1

4 files changed

+46
-0
lines changed

Diff for: pkg/sns/SnsConnectionFactory.php

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ private function establishConnection(): SnsClient
105105
}
106106
}
107107

108+
if (isset($this->config['http'])) {
109+
$config['http'] = $this->config['http'];
110+
}
111+
108112
$establishConnection = function () use ($config) {
109113
return (new Sdk(['Sns' => $config]))->createMultiRegionSns();
110114
};
@@ -134,6 +138,7 @@ private function parseDsn(string $dsn): array
134138
'lazy' => $dsn->getBool('lazy'),
135139
'endpoint' => $dsn->getString('endpoint'),
136140
'topic_arns' => $dsn->getArray('topic_arns', [])->toArray(),
141+
'http' => $dsn->getArray('http', [])->toArray(),
137142
]), function ($value) { return null !== $value; });
138143
}
139144

@@ -148,6 +153,7 @@ private function defaultConfig(): array
148153
'lazy' => true,
149154
'endpoint' => null,
150155
'topic_arns' => [],
156+
'http' => [],
151157
];
152158
}
153159
}

Diff for: pkg/sns/Tests/SnsConnectionFactoryConfigTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,22 @@ public static function provideConfigs()
174174
],
175175
],
176176
];
177+
178+
yield [
179+
['dsn' => 'sns:?http[connect_timout]=2&http[timeout]=5'],
180+
[
181+
'key' => null,
182+
'secret' => null,
183+
'token' => null,
184+
'region' => null,
185+
'version' => '2010-03-31',
186+
'lazy' => true,
187+
'endpoint' => null,
188+
'http' => [
189+
'connect_timeout' => '2',
190+
'timeout' => '5',
191+
],
192+
],
193+
];
177194
}
178195
}

Diff for: pkg/sqs/SqsConnectionFactory.php

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ private function establishConnection(): SqsClient
108108
}
109109
}
110110

111+
if (isset($this->config['http'])) {
112+
$config['http'] = $this->config['http'];
113+
}
114+
111115
$establishConnection = function () use ($config) {
112116
return (new Sdk(['Sqs' => $config]))->createMultiRegionSqs();
113117
};
@@ -139,6 +143,7 @@ private function parseDsn(string $dsn): array
139143
'endpoint' => $dsn->getString('endpoint'),
140144
'profile' => $dsn->getString('profile'),
141145
'queue_owner_aws_account_id' => $dsn->getString('queue_owner_aws_account_id'),
146+
'http' => $dsn->getArray('http', [])->toArray(),
142147
]), function ($value) { return null !== $value; });
143148
}
144149

@@ -155,6 +160,7 @@ private function defaultConfig(): array
155160
'endpoint' => null,
156161
'profile' => null,
157162
'queue_owner_aws_account_id' => null,
163+
'http' => [],
158164
];
159165
}
160166
}

Diff for: pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,22 @@ public static function provideConfigs()
205205
'queue_owner_aws_account_id' => null,
206206
],
207207
];
208+
209+
yield [
210+
['dsn' => 'sqs:?http[connect_timout]=2&http[timeout]=5'],
211+
[
212+
'key' => null,
213+
'secret' => null,
214+
'token' => null,
215+
'region' => null,
216+
'version' => '2010-03-31',
217+
'lazy' => true,
218+
'endpoint' => null,
219+
'http' => [
220+
'connect_timeout' => '2',
221+
'timeout' => '5',
222+
],
223+
],
224+
];
208225
}
209226
}

0 commit comments

Comments
 (0)