Skip to content

Commit 9acc6eb

Browse files
committed
multi client configuration
1 parent 3e9a367 commit 9acc6eb

3 files changed

Lines changed: 83 additions & 42 deletions

File tree

‎pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ class CustomAppKernel extends Kernel
1616
private $enqueueConfigId;
1717

1818
private $enqueueConfig = [
19-
'client' => [
20-
'prefix' => 'enqueue',
21-
'app_name' => '',
22-
'router_topic' => 'test',
23-
'router_queue' => 'test',
24-
'default_processor_queue' => 'test',
19+
'default' => [
20+
'client' => [
21+
'prefix' => 'enqueue',
22+
'app_name' => '',
23+
'router_topic' => 'test',
24+
'router_queue' => 'test',
25+
'default_processor_queue' => 'test',
26+
],
2527
],
2628
];
2729

2830
public function setEnqueueConfig(array $config)
2931
{
3032
$this->enqueueConfig = array_replace_recursive($this->enqueueConfig, $config);
31-
$this->enqueueConfig['client']['app_name'] = str_replace('.', '', uniqid('app_name', true));
33+
$this->enqueueConfig['default']['client']['app_name'] = str_replace('.', '', uniqid('app_name', true));
3234
$this->enqueueConfigId = md5(json_encode($this->enqueueConfig));
3335

3436
$fs = new Filesystem();

‎pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php‎

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,69 +50,91 @@ public function provideEnqueueConfigs()
5050
$this->assertDirectoryExists($certDir);
5151

5252
yield 'amqp_dsn' => [[
53-
'transport' => getenv('AMQP_DSN'),
53+
'default' => [
54+
'transport' => getenv('AMQP_DSN'),
55+
],
5456
]];
5557

5658
yield 'amqps_dsn' => [[
57-
'transport' => [
58-
'dsn' => getenv('AMQPS_DSN'),
59-
'ssl_verify' => false,
60-
'ssl_cacert' => $certDir.'/cacert.pem',
61-
'ssl_cert' => $certDir.'/cert.pem',
62-
'ssl_key' => $certDir.'/key.pem',
59+
'default' => [
60+
'transport' => [
61+
'dsn' => getenv('AMQPS_DSN'),
62+
'ssl_verify' => false,
63+
'ssl_cacert' => $certDir.'/cacert.pem',
64+
'ssl_cert' => $certDir.'/cert.pem',
65+
'ssl_key' => $certDir.'/key.pem',
66+
],
6367
],
6468
]];
6569

6670
yield 'dsn_as_env' => [[
67-
'transport' => '%env(AMQP_DSN)%',
71+
'default' => [
72+
'transport' => '%env(AMQP_DSN)%',
73+
],
6874
]];
6975

7076
yield 'dbal_dsn' => [[
71-
'transport' => getenv('DOCTRINE_DSN'),
77+
'default' => [
78+
'transport' => getenv('DOCTRINE_DSN'),
79+
],
7280
]];
7381

7482
yield 'rabbitmq_stomp' => [[
75-
'transport' => [
76-
'dsn' => getenv('RABITMQ_STOMP_DSN'),
77-
'lazy' => false,
78-
'management_plugin_installed' => true,
83+
'default' => [
84+
'transport' => [
85+
'dsn' => getenv('RABITMQ_STOMP_DSN'),
86+
'lazy' => false,
87+
'management_plugin_installed' => true,
88+
],
7989
],
8090
]];
8191

8292
yield 'predis_dsn' => [[
83-
'transport' => [
84-
'dsn' => getenv('PREDIS_DSN'),
85-
'lazy' => false,
93+
'default' => [
94+
'transport' => [
95+
'dsn' => getenv('PREDIS_DSN'),
96+
'lazy' => false,
97+
],
8698
],
8799
]];
88100

89101
yield 'phpredis_dsn' => [[
90-
'transport' => [
91-
'dsn' => getenv('PHPREDIS_DSN'),
92-
'lazy' => false,
102+
'default' => [
103+
'transport' => [
104+
'dsn' => getenv('PHPREDIS_DSN'),
105+
'lazy' => false,
106+
],
93107
],
94108
]];
95109

96110
yield 'fs_dsn' => [[
97-
'transport' => 'file://'.sys_get_temp_dir(),
111+
'default' => [
112+
'transport' => 'file://'.sys_get_temp_dir(),
113+
],
98114
]];
99115

100116
yield 'sqs' => [[
101-
'transport' => [
102-
'dsn' => getenv('SQS_DSN'),
117+
'default' => [
118+
'transport' => [
119+
'dsn' => getenv('SQS_DSN'),
120+
],
103121
],
104122
]];
105123

106124
yield 'sqs_client' => [[
107-
'transport' => [
108-
'dsn' => 'sqs:',
109-
'service' => 'test.sqs_client',
110-
'factory_service' => 'test.sqs_custom_connection_factory_factory',
125+
'default' => [
126+
'transport' => [
127+
'dsn' => 'sqs:',
128+
'service' => 'test.sqs_client',
129+
'factory_service' => 'test.sqs_custom_connection_factory_factory',
130+
],
111131
],
112132
]];
113133

114134
yield 'mongodb_dsn' => [[
115-
'transport' => getenv('MONGO_DSN'),
135+
'default' => [
136+
'transport' => getenv('MONGO_DSN'),
137+
],
116138
]];
117139
//
118140
// yield 'gps' => [[
@@ -166,7 +188,9 @@ public function testProducerSendsCommandMessage(array $enqueueConfig)
166188
public function testProducerSendsEventMessageViaProduceCommand()
167189
{
168190
$this->customSetUp([
169-
'transport' => getenv('AMQP_DSN'),
191+
'default' => [
192+
'transport' => getenv('AMQP_DSN'),
193+
],
170194
]);
171195

172196
$expectedBody = __METHOD__.time();
@@ -191,7 +215,9 @@ public function testProducerSendsEventMessageViaProduceCommand()
191215
public function testProducerSendsCommandMessageViaProduceCommand()
192216
{
193217
$this->customSetUp([
194-
'transport' => getenv('AMQP_DSN'),
218+
'default' => [
219+
'transport' => getenv('AMQP_DSN'),
220+
],
195221
]);
196222

197223
$expectedBody = __METHOD__.time();
@@ -217,7 +243,9 @@ public function testProducerSendsCommandMessageViaProduceCommand()
217243
public function testShouldSetupBroker()
218244
{
219245
$this->customSetUp([
220-
'transport' => 'file://'.sys_get_temp_dir(),
246+
'default' => [
247+
'transport' => 'file://'.sys_get_temp_dir(),
248+
],
221249
]);
222250

223251
$command = static::$container->get('test_enqueue.client.setup_broker_command');
@@ -230,7 +258,9 @@ public function testShouldSetupBroker()
230258
public function testClientConsumeCommandMessagesFromExplicitlySetQueue()
231259
{
232260
$this->customSetUp([
233-
'transport' => getenv('AMQP_DSN'),
261+
'default' => [
262+
'transport' => getenv('AMQP_DSN'),
263+
],
234264
]);
235265

236266
$command = static::$container->get('test_enqueue.client.consume_command');
@@ -255,7 +285,9 @@ public function testClientConsumeCommandMessagesFromExplicitlySetQueue()
255285
public function testClientConsumeMessagesFromExplicitlySetQueue()
256286
{
257287
$this->customSetUp([
258-
'transport' => getenv('AMQP_DSN'),
288+
'default' => [
289+
'transport' => getenv('AMQP_DSN'),
290+
],
259291
]);
260292

261293
$expectedBody = __METHOD__.time();
@@ -280,7 +312,9 @@ public function testClientConsumeMessagesFromExplicitlySetQueue()
280312
public function testTransportConsumeMessagesCommandShouldConsumeMessage()
281313
{
282314
$this->customSetUp([
283-
'transport' => getenv('AMQP_DSN'),
315+
'default' => [
316+
'transport' => getenv('AMQP_DSN'),
317+
],
284318
]);
285319

286320
if ($this->getTestQueue() instanceof StompDestination) {

‎pkg/enqueue/Symfony/Client/DependencyInjection/ClientFactory.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,24 @@ public function build(ContainerBuilder $container, array $config, bool $default
8080
->addArgument($this->reference('route_collection'))
8181
;
8282

83+
$routerProcessor = empty($config['router_processor'])
84+
? $this->format('router_processor')
85+
: $config['router_processor']
86+
;
87+
8388
$container->register($this->format('config'), Config::class)
8489
->setArguments([
8590
$config['prefix'],
8691
$config['app_name'],
8792
$config['router_topic'],
8893
$config['router_queue'],
8994
$config['default_processor_queue'],
90-
isset($config['router_processor']) ? $config['router_processor'] : $this->format('router_processor'),
95+
$routerProcessor,
9196
// @todo should be driver options.
9297
$config['transport'],
9398
]);
9499

95-
$container->setParameter($this->format('router_processor'), $config['router_processor']);
100+
$container->setParameter($this->format('router_processor'), $routerProcessor);
96101
$container->setParameter($this->format('router_queue_name'), $config['router_queue']);
97102
$container->setParameter($this->format('default_queue_name'), $config['default_processor_queue']);
98103

0 commit comments

Comments
 (0)