Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The ability to specify an array of hosts is added. #141

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 50 additions & 16 deletions Broker/AmqpLibFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,66 @@ public function getChannel($connection)
} else {
$ssl_opts = array();
foreach ($this->connections[$connection]['ssl_options'] as $key => $value) {
if (!empty($value)) {
if (isset($value)) {
$ssl_opts[$key] = $value;
}
}
}

$conn = new AMQPSSLConnection(
$this->connections[$connection]['host'],
$this->connections[$connection]['port'],
$this->connections[$connection]['login'],
$this->connections[$connection]['password'],
$this->connections[$connection]['vhost'],
$ssl_opts
);
if (!empty($this->connections[$connection]['link'])) {
$conn = AMQPSSLConnection::create_connection(
$this->mapMultiConnectionsParam($this->connections[$connection]['link']),
['ssl_options' => $ssl_opts]
);
} else {
$conn = new AMQPSSLConnection(
$this->connections[$connection]['host'],
$this->connections[$connection]['port'],
$this->connections[$connection]['login'],
$this->connections[$connection]['password'],
$this->connections[$connection]['vhost'],
$ssl_opts
);
}
} else {
$conn = new AMQPConnection(
$this->connections[$connection]['host'],
$this->connections[$connection]['port'],
$this->connections[$connection]['login'],
$this->connections[$connection]['password'],
$this->connections[$connection]['vhost']
);
if (!empty($this->connections[$connection]['link'])) {
$conn = AMQPConnection::create_connection(
$this->mapMultiConnectionsParam($this->connections[$connection]['link'])
);
} else {
$conn = new AMQPConnection(
$this->connections[$connection]['host'],
$this->connections[$connection]['port'],
$this->connections[$connection]['login'],
$this->connections[$connection]['password'],
$this->connections[$connection]['vhost']
);
}
}

$this->channels[$connection] = $conn->channel();

return $this->channels[$connection];
}

/**
* @param array $connections
*
* @return array
*/
private function mapMultiConnectionsParam(array $connections)
{
return array_map(
function ($param) {
return [
'host' => $param['host'],
'port' => $param['port'],
'user' => $param['login'],
'password' => $param['password'],
'vhost' => $param['vhost'],
];
},
$connections
);
}
}
30 changes: 29 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class Configuration implements ConfigurationInterface
{
private const PECL_PROVIDER = 'pecl';

protected $knownProcessors = array(
'ack' => 'Swarrot\Processor\Ack\AckProcessor',
'exception_catcher' => 'Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor',
Expand Down Expand Up @@ -43,6 +45,20 @@ public function getConfigTreeBuilder()
$v['logger'] = $v['publisher_logger'];
}

if (!isset($v['provider'])) {
$v['provider'] = self::PECL_PROVIDER;
}

if (self::PECL_PROVIDER === $v['provider'] && isset($v['connections'])) {
foreach ($v['connections'] as $connection) {
if (!empty($connection['link'])) {
throw new \UnexpectedValueException(
'Selected provider does not support parameter "link"'
);
}
}
}

if (!isset($v['consumers'])) {
$v['consumers'] = [];
}
Expand Down Expand Up @@ -93,7 +109,7 @@ public function getConfigTreeBuilder()
->fixXmlConfig('processor', 'processors_stack')
->children()
->scalarNode('provider')
->defaultValue('pecl')
->defaultValue(self::PECL_PROVIDER)
->cannotBeEmpty()
->end()
->scalarNode('default_connection')->defaultValue(null)->end()
Expand Down Expand Up @@ -129,6 +145,18 @@ public function getConfigTreeBuilder()
->scalarNode('local_cert')->end()
->end()
->end()

->arrayNode('link')
->arrayPrototype()
->children()
->scalarNode('host')->defaultValue('127.0.0.1')->end()
->integerNode('port')->defaultValue(5672)->end()
->scalarNode('login')->defaultValue('guest')->end()
->scalarNode('password')->defaultValue('guest')->end()
->scalarNode('vhost')->defaultValue('/')->end()
->end()
->end()
->end()
->end()
->end()
->end()
Expand Down
1 change: 1 addition & 0 deletions Tests/fixtures/default_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'cafile' => null,
'local_cert' => null,
],
'link' => []
],
],
'consumers' => [
Expand Down
1 change: 1 addition & 0 deletions Tests/fixtures/default_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ swarrot:
verify_peer: ~
cafile: ~
local_cert: ~
link: []
consumers:

# Prototype
Expand Down
1 change: 1 addition & 0 deletions Tests/fixtures/old_default_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'cafile' => null,
'local_cert' => null,
],
'link' => []
],
],
'consumers' => [
Expand Down
1 change: 1 addition & 0 deletions Tests/fixtures/old_default_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ swarrot:
verify_peer: ~
cafile: ~
local_cert: ~
link: []
consumers:

# Prototype
Expand Down