Skip to content

Commit 9a0466d

Browse files
committed
Merge pull request #363 from ikwattro/socket-option
added option to use SocketConnection instead of StreamConnection
2 parents 2eaa665 + cc23ade commit 9a0466d

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected function addConnections(ArrayNodeDefinition $node)
5858
->booleanNode('lazy')->defaultFalse()->end()
5959
->scalarNode('connection_timeout')->defaultValue(3)->end()
6060
->scalarNode('read_write_timeout')->defaultValue(3)->end()
61+
->booleanNode('use_socket')->defaultValue(false)->end()
6162
->arrayNode('ssl_context')
6263
->useAttributeAsKey('key')
6364
->canBeUnset()

DependencyInjection/OldSoundRabbitMqExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ public function load(array $configs, ContainerBuilder $container)
7171
protected function loadConnections()
7272
{
7373
foreach ($this->config['connections'] as $key => $connection) {
74+
$connectionSuffix = $connection['use_socket'] ? 'socket_connection.class' : 'connection.class';
7475
$classParam =
7576
$connection['lazy']
76-
? '%old_sound_rabbit_mq.lazy.connection.class%'
77-
: '%old_sound_rabbit_mq.connection.class%';
77+
? '%old_sound_rabbit_mq.lazy.'.$connectionSuffix.'%'
78+
: '%old_sound_rabbit_mq.'.$connectionSuffix.'%';
7879

7980
$definition = new Definition('%old_sound_rabbit_mq.connection_factory.class%', array(
8081
$classParam, $connection,

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ old_sound_rabbit_mq:
110110
111111
# requires php-amqplib v2.4.1+
112112
heartbeat: 0
113+
114+
#requires php_sockets.dll
115+
use_socket: true # default false
113116
producers:
114117
upload_picture:
115118
connection: default

Resources/config/rabbitmq.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
<parameters>
77
<parameter key="old_sound_rabbit_mq.connection.class">PhpAmqpLib\Connection\AMQPConnection</parameter>
8+
<parameter key="old_sound_rabbit_mq.socket_connection.class">PhpAmqpLib\Connection\AMQPSocketConnection</parameter>
89
<parameter key="old_sound_rabbit_mq.lazy.connection.class">PhpAmqpLib\Connection\AMQPLazyConnection</parameter>
10+
<parameter key="old_sound_rabbit_mq.lazy.socket_connection.class">PhpAmqpLib\Connection\AMQPLazySocketConnection</parameter>
911
<parameter key="old_sound_rabbit_mq.connection_factory.class">OldSound\RabbitMqBundle\RabbitMq\AMQPConnectionFactory</parameter>
1012
<parameter key="old_sound_rabbit_mq.binding.class">OldSound\RabbitMqBundle\RabbitMq\Binding</parameter>
1113
<parameter key="old_sound_rabbit_mq.producer.class">OldSound\RabbitMqBundle\RabbitMq\Producer</parameter>

Tests/DependencyInjection/Fixtures/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ old_sound_rabbit_mq:
2727
vhost: /lazy
2828
lazy: true
2929

30+
socket_connection:
31+
host: bar_host
32+
port: 789
33+
user: socket_user
34+
password: socket_password
35+
vhost: /socket
36+
lazy: false
37+
use_socket: true
38+
39+
lazy_socket:
40+
host: joe_host
41+
port: 987
42+
user: lazy_socket_user
43+
password: lazy_socket_password
44+
vhost: /lazy_socket
45+
lazy: true
46+
use_socket: true
47+
3048
default:
3149

3250
producers:

Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ public function testFooConnectionDefinition()
3131
'connection_timeout' => 3,
3232
'read_write_timeout' => 3,
3333
'ssl_context' => array(),
34-
'keepalive' => null,
34+
'keepalive' => false,
3535
'heartbeat' => 0,
36+
'use_socket' => false
3637
), $factory->getArgument(1));
3738
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
3839
}
@@ -58,8 +59,9 @@ public function testSslConnectionDefinition()
5859
'ssl_context' => array(
5960
'verify_peer' => false,
6061
),
61-
'keepalive' => null,
62+
'keepalive' => false,
6263
'heartbeat' => 0,
64+
'use_socket' => false
6365
), $factory->getArgument(1));
6466
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
6567
}
@@ -83,8 +85,9 @@ public function testLazyConnectionDefinition()
8385
'connection_timeout' => 3,
8486
'read_write_timeout' => 3,
8587
'ssl_context' => array(),
86-
'keepalive' => null,
88+
'keepalive' => false,
8789
'heartbeat' => 0,
90+
'use_socket' => false
8891
), $factory->getArgument(1));
8992
$this->assertEquals('%old_sound_rabbit_mq.lazy.connection.class%', $definition->getClass());
9093
}
@@ -108,12 +111,31 @@ public function testDefaultConnectionDefinition()
108111
'connection_timeout' => 3,
109112
'read_write_timeout' => 3,
110113
'ssl_context' => array(),
111-
'keepalive' => null,
114+
'keepalive' => false,
112115
'heartbeat' => 0,
116+
'use_socket' => false
113117
), $factory->getArgument(1));
114118
$this->assertEquals('%old_sound_rabbit_mq.connection.class%', $definition->getClass());
115119
}
116120

121+
public function testSocketConnectionDefinition()
122+
{
123+
$container = $this->getContainer('test.yml');
124+
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.socket_connection'));
125+
$definiton = $container->getDefinition('old_sound_rabbit_mq.connection.socket_connection');
126+
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.socket_connection'));
127+
$this->assertEquals('%old_sound_rabbit_mq.socket_connection.class%', $definiton->getClass());
128+
}
129+
130+
public function testLazySocketConnectionDefinition()
131+
{
132+
$container = $this->getContainer('test.yml');
133+
$this->assertTrue($container->has('old_sound_rabbit_mq.connection.lazy_socket'));
134+
$definiton = $container->getDefinition('old_sound_rabbit_mq.connection.lazy_socket');
135+
$this->assertTrue($container->has('old_sound_rabbit_mq.connection_factory.lazy_socket'));
136+
$this->assertEquals('%old_sound_rabbit_mq.lazy.socket_connection.class%', $definiton->getClass());
137+
}
138+
117139
public function testFooBinding()
118140
{
119141
$container = $this->getContainer('test.yml');

0 commit comments

Comments
 (0)