Skip to content

Commit

Permalink
Merge pull request #8 from FabianMartin/connection_options
Browse files Browse the repository at this point in the history
new connection options added
  • Loading branch information
williamespindola authored Jul 12, 2017
2 parents 0256fc6 + aeda998 commit 9d10861
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,28 @@ In the [README](https://github.com/videlalvaro/RabbitMqBundle/blob/master/README
$app->register(new RabbitServiceProvider(), [
'rabbit.connections' => [
'default' => [
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/'
'host' => 'localhost',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/',
'lazy' => false,
'connection_timeout' => 3,
'read_write_timeout' => 6,
'keepalive' => false,
'heartbeat' => 3
],
'another' => [
'host' => 'another_host',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/'
'host' => 'another_host',
'port' => 5672,
'user' => 'guest',
'password' => 'guest',
'vhost' => '/'
'lazy' => false,
'connection_timeout' => 3,
'read_write_timeout' => 6,
'keepalive' => false,
'heartbeat' => 3
]
],
'rabbit.producers' => [
Expand Down
49 changes: 22 additions & 27 deletions src/fiunchinho/Silex/Provider/RabbitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,28 @@ private function loadConnections(Container $container)
$connections = [];

foreach ($container['rabbit.connections'] as $name => $options) {
$lazyConnection = false;

if (isset($container['rabbit.connections'][$name]['lazy'])) {
if ($container['rabbit.connections'][$name]['lazy'] === true) {
$lazyConnection = true;
}
}

switch ($lazyConnection) {
case (true):
$connection = new AMQPLazyConnection(
$container['rabbit.connections'][$name]['host'],
$container['rabbit.connections'][$name]['port'],
$container['rabbit.connections'][$name]['user'],
$container['rabbit.connections'][$name]['password'],
$container['rabbit.connections'][$name]['vhost']
);
break;
default:
$connection = new AMQPConnection(
$container['rabbit.connections'][$name]['host'],
$container['rabbit.connections'][$name]['port'],
$container['rabbit.connections'][$name]['user'],
$container['rabbit.connections'][$name]['password'],
$container['rabbit.connections'][$name]['vhost']
);
}
$connectionClass = isset($options['lazy']) && $options['lazy'] ? AMQPLazyConnection::class : AMQPConnection::class;
$connectionTimeout = isset($options['connection_timeout']) ? $options['connection_timeout'] : 3;
$readWriteTimeout = isset($options['read_write_timeout']) ? $options['read_write_timeout'] : 6;
$keepalive = isset($options['keepalive']) ? $options['keepalive'] : false;
$heartbeat = isset($options['heartbeat']) ? $options['heartbeat'] : 3;

$connection = new $connectionClass(
$options['host'],
$options['port'],
$options['user'],
$options['password'],
$options['vhost'],
false,
'AMQPLAIN',
null,
'en_US',
$connectionTimeout,
$readWriteTimeout,
null,
$keepalive,
$heartbeat
);

$connections[$name] = $connection;
}
Expand Down

0 comments on commit 9d10861

Please sign in to comment.