Skip to content

Commit 9e1c85c

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 php-enqueue/enqueue-dev#1213
1 parent 7a877c9 commit 9e1c85c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

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
}

Tests/SqsConnectionFactoryConfigTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public static function provideConfigs()
6767
'endpoint' => null,
6868
'profile' => null,
6969
'queue_owner_aws_account_id' => null,
70+
'http' => [],
7071
],
7172
];
7273

@@ -83,6 +84,7 @@ public static function provideConfigs()
8384
'endpoint' => null,
8485
'profile' => null,
8586
'queue_owner_aws_account_id' => null,
87+
'http' => [],
8688
],
8789
];
8890

@@ -99,6 +101,7 @@ public static function provideConfigs()
99101
'endpoint' => null,
100102
'profile' => null,
101103
'queue_owner_aws_account_id' => null,
104+
'http' => [],
102105
],
103106
];
104107

@@ -115,6 +118,7 @@ public static function provideConfigs()
115118
'endpoint' => null,
116119
'profile' => null,
117120
'queue_owner_aws_account_id' => null,
121+
'http' => [],
118122
],
119123
];
120124

@@ -131,6 +135,7 @@ public static function provideConfigs()
131135
'endpoint' => null,
132136
'profile' => null,
133137
'queue_owner_aws_account_id' => null,
138+
'http' => [],
134139
],
135140
];
136141

@@ -147,6 +152,7 @@ public static function provideConfigs()
147152
'endpoint' => null,
148153
'profile' => 'staging',
149154
'queue_owner_aws_account_id' => null,
155+
'http' => [],
150156
],
151157
];
152158

@@ -163,6 +169,7 @@ public static function provideConfigs()
163169
'endpoint' => null,
164170
'profile' => null,
165171
'queue_owner_aws_account_id' => null,
172+
'http' => [],
166173
],
167174
];
168175

@@ -185,6 +192,7 @@ public static function provideConfigs()
185192
'endpoint' => 'http://localstack:1111',
186193
'profile' => null,
187194
'queue_owner_aws_account_id' => null,
195+
'http' => [],
188196
],
189197
];
190198

@@ -203,6 +211,27 @@ public static function provideConfigs()
203211
'endpoint' => null,
204212
'profile' => 'staging',
205213
'queue_owner_aws_account_id' => null,
214+
'http' => [],
215+
],
216+
];
217+
218+
yield [
219+
['dsn' => 'sqs:?http[timeout]=5&http[connect_timeout]=2'],
220+
[
221+
'key' => null,
222+
'secret' => null,
223+
'token' => null,
224+
'region' => null,
225+
'retries' => 3,
226+
'version' => '2012-11-05',
227+
'lazy' => true,
228+
'endpoint' => null,
229+
'profile' => null,
230+
'queue_owner_aws_account_id' => null,
231+
'http' => [
232+
'timeout' => '5',
233+
'connect_timeout' => '2',
234+
],
206235
],
207236
];
208237
}

Tests/SqsConnectionFactoryTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testCouldBeConstructedWithEmptyConfiguration()
3636
'endpoint' => null,
3737
'profile' => null,
3838
'queue_owner_aws_account_id' => null,
39+
'http' => [],
3940
], 'config', $factory);
4041
}
4142

@@ -54,6 +55,7 @@ public function testCouldBeConstructedWithCustomConfiguration()
5455
'endpoint' => null,
5556
'profile' => null,
5657
'queue_owner_aws_account_id' => null,
58+
'http' => [],
5759
], 'config', $factory);
5860
}
5961

0 commit comments

Comments
 (0)