Skip to content

Commit d41048a

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 8a83409 commit d41048a

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

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
}

Tests/SnsConnectionFactoryConfigTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static function provideConfigs()
6565
'lazy' => true,
6666
'endpoint' => null,
6767
'topic_arns' => [],
68+
'http' => [],
6869
],
6970
];
7071

@@ -79,6 +80,7 @@ public static function provideConfigs()
7980
'lazy' => true,
8081
'endpoint' => null,
8182
'topic_arns' => [],
83+
'http' => [],
8284
],
8385
];
8486

@@ -93,6 +95,7 @@ public static function provideConfigs()
9395
'lazy' => true,
9496
'endpoint' => null,
9597
'topic_arns' => [],
98+
'http' => [],
9699
],
97100
];
98101

@@ -107,6 +110,7 @@ public static function provideConfigs()
107110
'lazy' => false,
108111
'endpoint' => null,
109112
'topic_arns' => [],
113+
'http' => [],
110114
],
111115
];
112116

@@ -121,6 +125,7 @@ public static function provideConfigs()
121125
'lazy' => false,
122126
'endpoint' => null,
123127
'topic_arns' => [],
128+
'http' => [],
124129
],
125130
];
126131

@@ -135,6 +140,7 @@ public static function provideConfigs()
135140
'lazy' => false,
136141
'endpoint' => null,
137142
'topic_arns' => [],
143+
'http' => [],
138144
],
139145
];
140146

@@ -155,6 +161,7 @@ public static function provideConfigs()
155161
'lazy' => false,
156162
'endpoint' => 'http://localstack:1111',
157163
'topic_arns' => [],
164+
'http' => [],
158165
],
159166
];
160167

@@ -172,6 +179,25 @@ public static function provideConfigs()
172179
'topic1' => 'arn:aws:sns:us-east-1:123456789012:topic1',
173180
'topic2' => 'arn:aws:sns:us-west-2:123456789012:topic2',
174181
],
182+
'http' => [],
183+
],
184+
];
185+
186+
yield [
187+
['dsn' => 'sns:?http[timeout]=5&http[connect_timeout]=2'],
188+
[
189+
'key' => null,
190+
'secret' => null,
191+
'token' => null,
192+
'region' => null,
193+
'version' => '2010-03-31',
194+
'lazy' => true,
195+
'endpoint' => null,
196+
'topic_arns' => [],
197+
'http' => [
198+
'timeout' => '5',
199+
'connect_timeout' => '2',
200+
],
175201
],
176202
];
177203
}

Tests/SnsConnectionFactoryTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function testCouldBeConstructedWithEmptyConfiguration()
3333
'region' => null,
3434
'version' => '2010-03-31',
3535
'endpoint' => null,
36-
'topic_arns' => [],
36+
'topic_arns' => [],
37+
'http' => [],
3738
], 'config', $factory);
3839
}
3940

@@ -49,7 +50,8 @@ public function testCouldBeConstructedWithCustomConfiguration()
4950
'region' => null,
5051
'version' => '2010-03-31',
5152
'endpoint' => null,
52-
'topic_arns' => [],
53+
'topic_arns' => [],
54+
'http' => [],
5355
], 'config', $factory);
5456
}
5557

0 commit comments

Comments
 (0)