Skip to content

Commit 3e4d486

Browse files
committed
multi client configuration
1 parent bc0071d commit 3e4d486

File tree

13 files changed

+114
-77
lines changed

13 files changed

+114
-77
lines changed

pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private function loadMessageQueueCollector(array $config, ContainerBuilder $cont
320320
$service = $container->register('enqueue.profiler.message_queue_collector', MessageQueueCollector::class);
321321
$service->addTag('data_collector', [
322322
'template' => '@Enqueue/Profiler/panel.html.twig',
323-
'id' => 'enqueue.message_queue'
323+
'id' => 'enqueue.message_queue',
324324
]);
325325

326326
foreach ($configNames as $configName) {

pkg/enqueue-bundle/Resources/config/services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
class: 'Enqueue\Symfony\Consumption\ConfigurableConsumeCommand'
1010
arguments:
1111
- '@enqueue.locator'
12+
- '%enqueue.default_transport%'
1213
- 'enqueue.transport.%s.queue_consumer'
1314
- 'enqueue.transport.%s.processor_registry'
1415
tags:
@@ -18,6 +19,7 @@ services:
1819
class: 'Enqueue\Symfony\Client\ConsumeCommand'
1920
arguments:
2021
- '@enqueue.locator'
22+
- '%enqueue.default_client%'
2123
- 'enqueue.client.%s.queue_consumer'
2224
- 'enqueue.client.%s.driver'
2325
- 'enqueue.client.%s.delegate_processor'
@@ -28,6 +30,7 @@ services:
2830
class: 'Enqueue\Symfony\Client\ProduceCommand'
2931
arguments:
3032
- '@enqueue.locator'
33+
- '%enqueue.default_client%'
3134
- 'enqueue.client.%s.producer'
3235
tags:
3336
- { name: 'console.command' }
@@ -36,6 +39,7 @@ services:
3639
class: 'Enqueue\Symfony\Client\SetupBrokerCommand'
3740
arguments:
3841
- '@enqueue.locator'
42+
- '%enqueue.default_client%'
3943
- 'enqueue.client.%s.driver'
4044
tags:
4145
- { name: 'console.command' }
@@ -44,6 +48,7 @@ services:
4448
class: 'Enqueue\Symfony\Client\RoutesCommand'
4549
arguments:
4650
- '@enqueue.locator'
51+
- '%enqueue.default_client%'
4752
- 'enqueue.client.%s.driver'
4853
tags:
4954
- { name: 'console.command' }

pkg/enqueue/Symfony/Client/ConsumeCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class ConsumeCommand extends Command
3434
*/
3535
private $container;
3636

37+
/**
38+
* @var string
39+
*/
40+
private $defaultClient;
41+
3742
/**
3843
* @var string
3944
*/
@@ -51,16 +56,18 @@ class ConsumeCommand extends Command
5156

5257
public function __construct(
5358
ContainerInterface $container,
59+
string $defaultClient,
5460
string $queueConsumerIdPattern = 'enqueue.client.%s.queue_consumer',
5561
string $driverIdPattern = 'enqueue.client.%s.driver',
5662
string $processorIdPatter = 'enqueue.client.%s.delegate_processor'
5763
) {
58-
parent::__construct(self::$defaultName);
59-
6064
$this->container = $container;
65+
$this->defaultClient = $defaultClient;
6166
$this->queueConsumerIdPattern = $queueConsumerIdPattern;
6267
$this->driverIdPattern = $driverIdPattern;
6368
$this->processorIdPattern = $processorIdPatter;
69+
70+
parent::__construct(self::$defaultName);
6471
}
6572

6673
protected function configure(): void
@@ -77,7 +84,7 @@ protected function configure(): void
7784
'It select an appropriate message processor based on a message headers')
7885
->addArgument('client-queue-names', InputArgument::IS_ARRAY, 'Queues to consume messages from')
7986
->addOption('skip', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Queues to skip consumption of messages from', [])
80-
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', 'default')
87+
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', $this->defaultClient)
8188
;
8289
}
8390

pkg/enqueue/Symfony/Client/ProduceCommand.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ class ProduceCommand extends Command
2020
*/
2121
private $container;
2222

23+
/**
24+
* @var string
25+
*/
26+
private $defaultClient;
27+
2328
/**
2429
* @var string
2530
*/
2631
private $producerIdPattern;
2732

28-
public function __construct(ContainerInterface $container, string $producerIdPattern = 'enqueue.client.%s.producer')
33+
public function __construct(ContainerInterface $container, string $defaultClient, string $producerIdPattern = 'enqueue.client.%s.producer')
2934
{
30-
parent::__construct(static::$defaultName);
31-
3235
$this->container = $container;
36+
$this->defaultClient = $defaultClient;
3337
$this->producerIdPattern = $producerIdPattern;
38+
39+
parent::__construct(static::$defaultName);
3440
}
3541

3642
protected function configure(): void
3743
{
3844
$this
3945
->setDescription('Sends an event to the topic')
4046
->addArgument('message', InputArgument::REQUIRED, 'A message')
41-
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', 'default')
47+
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', $this->defaultClient)
4248
->addOption('topic', null, InputOption::VALUE_OPTIONAL, 'The topic to send a message to')
4349
->addOption('command', null, InputOption::VALUE_OPTIONAL, 'The command to send a message to')
4450
;

pkg/enqueue/Symfony/Client/RoutesCommand.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class RoutesCommand extends Command
2222
*/
2323
private $container;
2424

25+
/**
26+
* @var string
27+
*/
28+
private $defaultClient;
29+
2530
/**
2631
* @var string
2732
*/
@@ -32,12 +37,13 @@ class RoutesCommand extends Command
3237
*/
3338
private $driver;
3439

35-
public function __construct(ContainerInterface $container, string $driverIdPatter = 'enqueue.client.%s.driver')
40+
public function __construct(ContainerInterface $container, string $defaultClient, string $driverIdPatter = 'enqueue.client.%s.driver')
3641
{
37-
parent::__construct(static::$defaultName);
38-
3942
$this->container = $container;
43+
$this->defaultClient = $defaultClient;
4044
$this->driverIdPatter = $driverIdPatter;
45+
46+
parent::__construct(static::$defaultName);
4147
}
4248

4349
protected function configure(): void
@@ -46,7 +52,7 @@ protected function configure(): void
4652
->setAliases(['debug:enqueue:routes'])
4753
->setDescription('A command lists all registered routes.')
4854
->addOption('show-route-options', null, InputOption::VALUE_NONE, 'Adds ability to hide options.')
49-
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', 'default')
55+
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', $this->defaultClient)
5056
;
5157

5258
$this->driver = null;

pkg/enqueue/Symfony/Client/SetupBrokerCommand.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ class SetupBrokerCommand extends Command
2020
*/
2121
private $container;
2222

23+
/**
24+
* @var string
25+
*/
26+
private $defaultClient;
27+
2328
/**
2429
* @var string
2530
*/
2631
private $driverIdPattern;
2732

28-
public function __construct(ContainerInterface $container, string $driverIdPattern = 'enqueue.client.%s.driver')
33+
public function __construct(ContainerInterface $container, string $defaultClient, string $driverIdPattern = 'enqueue.client.%s.driver')
2934
{
30-
parent::__construct(static::$defaultName);
31-
3235
$this->container = $container;
36+
$this->defaultClient = $defaultClient;
3337
$this->driverIdPattern = $driverIdPattern;
38+
39+
parent::__construct(static::$defaultName);
3440
}
3541

3642
protected function configure(): void
3743
{
3844
$this
3945
->setAliases(['enq:sb'])
4046
->setDescription('Setup broker. Configure the broker, creates queues, topics and so on.')
41-
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', 'default')
47+
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', $this->defaultClient)
4248
;
4349
}
4450

pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class ConfigurableConsumeCommand extends Command
2727
*/
2828
private $container;
2929

30+
/**
31+
* @var string
32+
*/
33+
private $defaultTransport;
34+
3035
/**
3136
* @var string
3237
*/
@@ -39,14 +44,16 @@ class ConfigurableConsumeCommand extends Command
3944

4045
public function __construct(
4146
ContainerInterface $container,
47+
string $defaultTransport,
4248
string $queueConsumerIdPattern = 'enqueue.transport.%s.queue_consumer',
4349
string $processorRegistryIdPattern = 'enqueue.transport.%s.processor_registry'
4450
) {
45-
parent::__construct(static::$defaultName);
46-
4751
$this->container = $container;
52+
$this->defaultTransport = $defaultTransport;
4853
$this->queueConsumerIdPattern = $queueConsumerIdPattern;
4954
$this->processorRegistryIdPattern = $processorRegistryIdPattern;
55+
56+
parent::__construct(static::$defaultName);
5057
}
5158

5259
protected function configure(): void
@@ -61,7 +68,7 @@ protected function configure(): void
6168
'and a message processor service')
6269
->addArgument('processor', InputArgument::REQUIRED, 'A message processor.')
6370
->addArgument('queues', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'A queue to consume from', [])
64-
->addOption('transport', 't', InputOption::VALUE_OPTIONAL, 'The transport to consume messages from.', 'default')
71+
->addOption('transport', 't', InputOption::VALUE_OPTIONAL, 'The transport to consume messages from.', $this->defaultTransport)
6572
;
6673
}
6774

pkg/enqueue/Tests/Client/TraceableProducerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testShouldCollectInfoIfStringGivenAsEventMessage()
6060
'messageId' => null,
6161
],
6262
], $producer->getTraces());
63-
63+
6464
$this->assertArrayHasKey('sentAt', $producer->getTraces()[0]);
6565
}
6666

pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ public function testShouldNotBeFinal()
3434

3535
public function testCouldBeConstructedWithRequiredAttributes()
3636
{
37-
new ConsumeCommand($this->createMock(ContainerInterface::class));
37+
new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
3838
}
3939

4040
public function testShouldHaveCommandName()
4141
{
42-
$command = new ConsumeCommand($this->createMock(ContainerInterface::class));
42+
$command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
4343

4444
$this->assertEquals('enqueue:consume', $command->getName());
4545
}
4646

4747
public function testShouldHaveExpectedOptions()
4848
{
49-
$command = new ConsumeCommand($this->createMock(ContainerInterface::class));
49+
$command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
5050

5151
$options = $command->getDefinition()->getOptions();
5252

@@ -64,7 +64,7 @@ public function testShouldHaveExpectedOptions()
6464

6565
public function testShouldHaveExpectedAttributes()
6666
{
67-
$command = new ConsumeCommand($this->createMock(ContainerInterface::class));
67+
$command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default');
6868

6969
$arguments = $command->getDefinition()->getArguments();
7070

@@ -104,7 +104,7 @@ public function testShouldBindDefaultQueueOnly()
104104
'enqueue.client.default.queue_consumer' => $consumer,
105105
'enqueue.client.default.driver' => $driver,
106106
'enqueue.client.default.delegate_processor' => $processor,
107-
]));
107+
]), 'default');
108108

109109
$tester = new CommandTester($command);
110110
$tester->execute([]);
@@ -164,7 +164,7 @@ public function testShouldUseRequestedClient()
164164
'enqueue.client.foo.queue_consumer' => $fooConsumer,
165165
'enqueue.client.foo.driver' => $fooDriver,
166166
'enqueue.client.foo.delegate_processor' => $fooProcessor,
167-
]));
167+
]), 'default');
168168

169169
$tester = new CommandTester($command);
170170
$tester->execute([
@@ -198,7 +198,7 @@ public function testThrowIfNotDefinedClientRequested()
198198
'enqueue.client.default.queue_consumer' => $consumer,
199199
'enqueue.client.default.driver' => $driver,
200200
'enqueue.client.default.delegate_processor' => $processor,
201-
]));
201+
]), 'default');
202202

203203
$tester = new CommandTester($command);
204204

@@ -243,7 +243,7 @@ public function testShouldBindDefaultQueueIfRouteUseDifferentQueue()
243243
'enqueue.client.default.queue_consumer' => $consumer,
244244
'enqueue.client.default.driver' => $driver,
245245
'enqueue.client.default.delegate_processor' => $processor,
246-
]));
246+
]), 'default');
247247

248248
$tester = new CommandTester($command);
249249
$tester->execute([]);
@@ -295,7 +295,7 @@ public function testShouldBindCustomExecuteConsumptionAndUseCustomClientDestinat
295295
'enqueue.client.default.queue_consumer' => $consumer,
296296
'enqueue.client.default.driver' => $driver,
297297
'enqueue.client.default.delegate_processor' => $processor,
298-
]));
298+
]), 'default');
299299

300300
$tester = new CommandTester($command);
301301
$tester->execute([]);
@@ -336,7 +336,7 @@ public function testShouldBindUserProvidedQueues()
336336
'enqueue.client.default.queue_consumer' => $consumer,
337337
'enqueue.client.default.driver' => $driver,
338338
'enqueue.client.default.delegate_processor' => $processor,
339-
]));
339+
]), 'default');
340340

341341
$tester = new CommandTester($command);
342342
$tester->execute([
@@ -378,7 +378,7 @@ public function testShouldBindNotPrefixedQueue()
378378
'enqueue.client.default.queue_consumer' => $consumer,
379379
'enqueue.client.default.driver' => $driver,
380380
'enqueue.client.default.delegate_processor' => $processor,
381-
]));
381+
]), 'default');
382382

383383
$tester = new CommandTester($command);
384384
$tester->execute([
@@ -434,7 +434,7 @@ public function testShouldBindQueuesOnlyOnce()
434434
'enqueue.client.default.queue_consumer' => $consumer,
435435
'enqueue.client.default.driver' => $driver,
436436
'enqueue.client.default.delegate_processor' => $processor,
437-
]));
437+
]), 'default');
438438

439439
$tester = new CommandTester($command);
440440
$tester->execute([]);
@@ -475,7 +475,7 @@ public function testShouldNotBindExternalRoutes()
475475
'enqueue.client.default.queue_consumer' => $consumer,
476476
'enqueue.client.default.driver' => $driver,
477477
'enqueue.client.default.delegate_processor' => $processor,
478-
]));
478+
]), 'default');
479479

480480
$tester = new CommandTester($command);
481481
$tester->execute([]);
@@ -528,7 +528,7 @@ public function testShouldSkipQueueConsumptionAndUseCustomClientDestinationName(
528528
'enqueue.client.default.queue_consumer' => $consumer,
529529
'enqueue.client.default.driver' => $driver,
530530
'enqueue.client.default.delegate_processor' => $processor,
531-
]));
531+
]), 'default');
532532

533533
$tester = new CommandTester($command);
534534
$tester->execute([

0 commit comments

Comments
 (0)