Skip to content

Commit 9117576

Browse files
authored
Add bundle configuration for login_method for RabbitMQ connections (#723)
1 parent a80937c commit 9117576

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- 2024-03-18
2+
* Add bundle configuration for `login_method` for RabbitMQ connections, this allow to configure other values than default AMQPLAIN (PLAIN or EXTERNAL), see https://www.rabbitmq.com/docs/access-control#mechanisms
3+
14
- 2023-11-07
25
* Add consumer option `no_ack`
36

DependencyInjection/Configuration.php

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OldSound\RabbitMqBundle\DependencyInjection;
44

55
use OldSound\RabbitMqBundle\RabbitMq\Producer;
6+
use PhpAmqpLib\Connection\AMQPConnectionConfig;
67
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
78
use Symfony\Component\Config\Definition\ConfigurationInterface;
89
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
@@ -73,6 +74,14 @@ protected function addConnections(ArrayNodeDefinition $node)
7374
->scalarNode('user')->defaultValue('guest')->end()
7475
->scalarNode('password')->defaultValue('guest')->end()
7576
->scalarNode('vhost')->defaultValue('/')->end()
77+
->enumNode('login_method')
78+
->values([
79+
AMQPConnectionConfig::AUTH_AMQPPLAIN,
80+
AMQPConnectionConfig::AUTH_PLAIN,
81+
AMQPConnectionConfig::AUTH_EXTERNAL
82+
])
83+
->defaultValue(AMQPConnectionConfig::AUTH_AMQPPLAIN)
84+
->end()
7685
->arrayNode('hosts')
7786
->info('connection_timeout, read_write_timeout, use_socket, ssl_context, keepalive,
7887
heartbeat and connection_parameters_provider should be specified globally when

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ old_sound_rabbit_mq:
125125

126126
#requires php_sockets.dll
127127
use_socket: true # default false
128+
129+
login_method: 'AMQPLAIN' # default 'AMQPLAIN', can be 'EXTERNAL' or 'PLAIN', see https://www.rabbitmq.com/docs/access-control#mechanisms
130+
128131
another:
129132
# A different (unused) connection defined by an URL. One can omit all parts,
130133
# except the scheme (amqp:). If both segment in the URL and a key value (see above)

Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testFooConnectionDefinition()
4040
'url' => '',
4141
'hosts' => [],
4242
'channel_rpc_timeout' => 0.0,
43+
'login_method' => 'AMQPLAIN',
4344

4445
], $factory->getArgument(1));
4546
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
@@ -72,6 +73,7 @@ public function testSslConnectionDefinition()
7273
'url' => '',
7374
'hosts' => [],
7475
'channel_rpc_timeout' => 0.0,
76+
'login_method' => 'AMQPLAIN',
7577
], $factory->getArgument(1));
7678
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
7779
}
@@ -101,6 +103,7 @@ public function testLazyConnectionDefinition()
101103
'url' => '',
102104
'hosts' => [],
103105
'channel_rpc_timeout' => 0.0,
106+
'login_method' => 'AMQPLAIN',
104107
], $factory->getArgument(1));
105108
$this->assertEquals('%old_sound_rabbit_mq.lazy.connection.class%', $definition->getClass());
106109
}
@@ -130,6 +133,7 @@ public function testDefaultConnectionDefinition()
130133
'url' => '',
131134
'hosts' => [],
132135
'channel_rpc_timeout' => 0.0,
136+
'login_method' => 'AMQPLAIN',
133137
], $factory->getArgument(1));
134138
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
135139
}
@@ -194,6 +198,7 @@ public function testClusterConnectionDefinition()
194198
'use_socket' => false,
195199
'url' => '',
196200
'channel_rpc_timeout' => 0.0,
201+
'login_method' => 'AMQPLAIN',
197202
], $factory->getArgument(1));
198203
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
199204
}

0 commit comments

Comments
 (0)