Skip to content

Commit bc0071d

Browse files
committed
multi client configuration
1 parent d43798b commit bc0071d

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,25 @@ public function load(array $configs, ContainerBuilder $container): void
8686
}
8787
}
8888

89+
$defaultClient = null;
90+
if (in_array($defaultName, $clientNames, true)) {
91+
$defaultClient = $defaultName;
92+
}
93+
8994
$container->setParameter('enqueue.transports', $transportNames);
9095
$container->setParameter('enqueue.clients', $clientNames);
9196

97+
$container->setParameter('enqueue.default_transport', $defaultName);
98+
99+
if ($defaultClient) {
100+
$container->setParameter('enqueue.default_client', $defaultClient);
101+
}
102+
103+
if ($defaultClient) {
104+
$this->setupAutowiringForDefaultClientsProcessors($container, $defaultClient);
105+
}
106+
92107
$this->loadMessageQueueCollector($config, $container);
93-
$this->setupAutowiringForProcessors($config, $container);
94108
$this->loadAsyncCommands($config, $container);
95109

96110
// extensions
@@ -167,31 +181,18 @@ private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $contain
167181
}
168182
}
169183

170-
private function setupAutowiringForProcessors(array $config, ContainerBuilder $container)
184+
private function setupAutowiringForDefaultClientsProcessors(ContainerBuilder $container, string $defaultClient)
171185
{
172-
$configNames = [];
173-
foreach ($config as $name => $modules) {
174-
if (isset($modules['client'])) {
175-
$configNames[] = $name;
176-
}
177-
}
178-
179-
if (false == $configNames) {
180-
return;
181-
}
182-
183-
$topicSubscriber = $container->registerForAutoconfiguration(TopicSubscriberInterface::class)
186+
$container->registerForAutoconfiguration(TopicSubscriberInterface::class)
184187
->setPublic(true)
188+
->addTag('enqueue.topic_subscriber', ['client' => $defaultClient])
185189
;
186190

187-
$commandSubscriber = $container->registerForAutoconfiguration(CommandSubscriberInterface::class)
191+
$container->registerForAutoconfiguration(CommandSubscriberInterface::class)
188192
->setPublic(true)
193+
->addTag('enqueue.command_subscriber', ['client' => $defaultClient])
189194
;
190195

191-
foreach ($configNames as $configName) {
192-
$topicSubscriber->addTag('enqueue.topic_subscriber', ['client' => $configName]);
193-
$commandSubscriber->addTag('enqueue.command_subscriber', ['client' => $configName]);
194-
}
195196
}
196197

197198
private function loadDoctrinePingConnectionExtension(array $config, ContainerBuilder $container): void

pkg/enqueue-bundle/Tests/Unit/Profiler/MessageQueueCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testShouldReturnSentMessageArrayTakenFromTraceableProducers()
5858

5959
$collector->collect(new Request(), new Response());
6060

61-
$this->assertEquals(
61+
$this->assertArraySubset(
6262
[
6363
'foo' => [
6464
[

pkg/enqueue/Tests/Client/TraceableProducerTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testShouldCollectInfoIfStringGivenAsEventMessage()
4545

4646
$producer->sendEvent('aFooTopic', 'aFooBody');
4747

48-
$this->assertSame([
48+
$this->assertArraySubset([
4949
[
5050
'topic' => 'aFooTopic',
5151
'command' => null,
@@ -60,6 +60,8 @@ public function testShouldCollectInfoIfStringGivenAsEventMessage()
6060
'messageId' => null,
6161
],
6262
], $producer->getTraces());
63+
64+
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
6365
}
6466

6567
public function testShouldCollectInfoIfArrayGivenAsEventMessage()
@@ -68,7 +70,7 @@ public function testShouldCollectInfoIfArrayGivenAsEventMessage()
6870

6971
$producer->sendEvent('aFooTopic', ['foo' => 'fooVal', 'bar' => 'barVal']);
7072

71-
$this->assertSame([
73+
$this->assertArraySubset([
7274
[
7375
'topic' => 'aFooTopic',
7476
'command' => null,
@@ -83,6 +85,8 @@ public function testShouldCollectInfoIfArrayGivenAsEventMessage()
8385
'messageId' => null,
8486
],
8587
], $producer->getTraces());
88+
89+
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
8690
}
8791

8892
public function testShouldCollectInfoIfEventMessageObjectGivenAsMessage()
@@ -102,7 +106,7 @@ public function testShouldCollectInfoIfEventMessageObjectGivenAsMessage()
102106

103107
$producer->sendEvent('aFooTopic', $message);
104108

105-
$this->assertSame([
109+
$this->assertArraySubset([
106110
[
107111
'topic' => 'aFooTopic',
108112
'command' => null,
@@ -117,6 +121,8 @@ public function testShouldCollectInfoIfEventMessageObjectGivenAsMessage()
117121
'messageId' => 'theMessageId',
118122
],
119123
], $producer->getTraces());
124+
125+
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
120126
}
121127

122128
public function testShouldNotStoreAnythingIfInternalEventMessageProducerThrowsException()
@@ -162,7 +168,7 @@ public function testShouldCollectInfoIfStringGivenAsCommandMessage()
162168

163169
$producer->sendCommand('aFooCommand', 'aFooBody');
164170

165-
$this->assertSame([
171+
$this->assertArraySubset([
166172
[
167173
'topic' => null,
168174
'command' => 'aFooCommand',
@@ -177,6 +183,8 @@ public function testShouldCollectInfoIfStringGivenAsCommandMessage()
177183
'messageId' => null,
178184
],
179185
], $producer->getTraces());
186+
187+
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
180188
}
181189

182190
public function testShouldCollectInfoIfArrayGivenAsCommandMessage()
@@ -185,7 +193,7 @@ public function testShouldCollectInfoIfArrayGivenAsCommandMessage()
185193

186194
$producer->sendCommand('aFooCommand', ['foo' => 'fooVal', 'bar' => 'barVal']);
187195

188-
$this->assertSame([
196+
$this->assertArraySubset([
189197
[
190198
'topic' => null,
191199
'command' => 'aFooCommand',
@@ -200,6 +208,8 @@ public function testShouldCollectInfoIfArrayGivenAsCommandMessage()
200208
'messageId' => null,
201209
],
202210
], $producer->getTraces());
211+
212+
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
203213
}
204214

205215
public function testShouldCollectInfoIfCommandMessageObjectGivenAsMessage()
@@ -219,7 +229,7 @@ public function testShouldCollectInfoIfCommandMessageObjectGivenAsMessage()
219229

220230
$producer->sendCommand('aFooCommand', $message);
221231

222-
$this->assertSame([
232+
$this->assertArraySubset([
223233
[
224234
'topic' => null,
225235
'command' => 'aFooCommand',
@@ -234,6 +244,8 @@ public function testShouldCollectInfoIfCommandMessageObjectGivenAsMessage()
234244
'messageId' => 'theMessageId',
235245
],
236246
], $producer->getTraces());
247+
248+
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
237249
}
238250

239251
public function testShouldNotStoreAnythingIfInternalCommandMessageProducerThrowsException()

0 commit comments

Comments
 (0)