Skip to content

added option to use SocketConnection instead of StreamConnection #363

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

Merged
merged 2 commits into from
Jun 3, 2016
Merged
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
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function addConnections(ArrayNodeDefinition $node)
->booleanNode('lazy')->defaultFalse()->end()
->scalarNode('connection_timeout')->defaultValue(3)->end()
->scalarNode('read_write_timeout')->defaultValue(3)->end()
->booleanNode('use_socket')->defaultValue(false)->end()
->arrayNode('ssl_context')
->useAttributeAsKey('key')
->canBeUnset()
Expand Down
5 changes: 3 additions & 2 deletions DependencyInjection/OldSoundRabbitMqExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public function load(array $configs, ContainerBuilder $container)
protected function loadConnections()
{
foreach ($this->config['connections'] as $key => $connection) {
$connectionSuffix = $connection['use_socket'] ? 'socket_connection.class' : 'connection.class';
$classParam =
$connection['lazy']
? '%old_sound_rabbit_mq.lazy.connection.class%'
: '%old_sound_rabbit_mq.connection.class%';
? '%old_sound_rabbit_mq.lazy.'.$connectionSuffix.'%'
: '%old_sound_rabbit_mq.'.$connectionSuffix.'%';

$definition = new Definition('%old_sound_rabbit_mq.connection_factory.class%', array(
$classParam, $connection,
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ old_sound_rabbit_mq:
# requires php-amqplib v2.4.1+
heartbeat: 0
#requires php_sockets.dll
use_socket: true # default false
producers:
upload_picture:
connection: default
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/rabbitmq.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

<parameters>
<parameter key="old_sound_rabbit_mq.connection.class">PhpAmqpLib\Connection\AMQPConnection</parameter>
<parameter key="old_sound_rabbit_mq.socket_connection.class">PhpAmqpLib\Connection\AMQPSocketConnection</parameter>
<parameter key="old_sound_rabbit_mq.lazy.connection.class">PhpAmqpLib\Connection\AMQPLazyConnection</parameter>
<parameter key="old_sound_rabbit_mq.lazy.socket_connection.class">PhpAmqpLib\Connection\AMQPLazySocketConnection</parameter>
<parameter key="old_sound_rabbit_mq.connection_factory.class">OldSound\RabbitMqBundle\RabbitMq\AMQPConnectionFactory</parameter>
<parameter key="old_sound_rabbit_mq.binding.class">OldSound\RabbitMqBundle\RabbitMq\Binding</parameter>
<parameter key="old_sound_rabbit_mq.producer.class">OldSound\RabbitMqBundle\RabbitMq\Producer</parameter>
Expand Down
18 changes: 18 additions & 0 deletions Tests/DependencyInjection/Fixtures/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ old_sound_rabbit_mq:
vhost: /lazy
lazy: true

socket_connection:
host: bar_host
port: 789
user: socket_user
password: socket_password
vhost: /socket
lazy: false
use_socket: true

lazy_socket:
host: joe_host
port: 987
user: lazy_socket_user
password: lazy_socket_password
vhost: /lazy_socket
lazy: true
use_socket: true

default:

producers:
Expand Down
30 changes: 26 additions & 4 deletions Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public function testFooConnectionDefinition()
'connection_timeout' => 3,
'read_write_timeout' => 3,
'ssl_context' => array(),
'keepalive' => null,
'keepalive' => false,
'heartbeat' => 0,
'use_socket' => false
), $factory->getArgument(1));
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
}
Expand All @@ -58,8 +59,9 @@ public function testSslConnectionDefinition()
'ssl_context' => array(
'verify_peer' => false,
),
'keepalive' => null,
'keepalive' => false,
'heartbeat' => 0,
'use_socket' => false
), $factory->getArgument(1));
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
}
Expand All @@ -83,8 +85,9 @@ public function testLazyConnectionDefinition()
'connection_timeout' => 3,
'read_write_timeout' => 3,
'ssl_context' => array(),
'keepalive' => null,
'keepalive' => false,
'heartbeat' => 0,
'use_socket' => false
), $factory->getArgument(1));
$this->assertEquals('%old_sound_rabbit_mq.lazy.connection.class%', $definition->getClass());
}
Expand All @@ -108,12 +111,31 @@ public function testDefaultConnectionDefinition()
'connection_timeout' => 3,
'read_write_timeout' => 3,
'ssl_context' => array(),
'keepalive' => null,
'keepalive' => false,
'heartbeat' => 0,
'use_socket' => false
), $factory->getArgument(1));
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
}

public function testSocketConnectionDefinition()
{
$container = $this->getContainer('test.yml');
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.socket_connection'));
$definiton = $container->getDefinition('old_sound_rabbit_mq.connection.socket_connection');
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.socket_connection'));
$this->assertEquals('%old_sound_rabbit_mq.socket_connection.class%', $definiton->getClass());
}

public function testLazySocketConnectionDefinition()
{
$container = $this->getContainer('test.yml');
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.lazy_socket'));
$definiton = $container->getDefinition('old_sound_rabbit_mq.connection.lazy_socket');
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.lazy_socket'));
$this->assertEquals('%old_sound_rabbit_mq.lazy.socket_connection.class%', $definiton->getClass());
}

public function testFooBinding()
{
$container = $this->getContainer('test.yml');
Expand Down