Skip to content

Commit

Permalink
Merge pull request #536 from php-enqueue/amqp-set-delay-strategy-if-r…
Browse files Browse the repository at this point in the history
…abbitmq-scheme-extension

[amqp] Set delay strategy if rabbitmq scheme extension present.
  • Loading branch information
makasim authored Sep 17, 2018
2 parents e5dcdc5 + 3725995 commit b9c49c6
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 229 deletions.
6 changes: 5 additions & 1 deletion pkg/amqp-bunny/AmqpConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Enqueue\AmqpTools\ConnectionConfig;
use Enqueue\AmqpTools\DelayStrategyAware;
use Enqueue\AmqpTools\DelayStrategyAwareTrait;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
use Interop\Queue\PsrContext;

Expand All @@ -33,10 +34,13 @@ public function __construct($config = 'amqp:')
{
$this->config = (new ConnectionConfig($config))
->addSupportedScheme('amqp+bunny')
->addDefaultOption('receive_method', 'basic_get')
->addDefaultOption('tcp_nodelay', null)
->parse()
;

if (in_array('rabbitmq', $this->config->getSchemeExtensions(), true)) {
$this->setDelayStrategy(new RabbitMqDlxDelayStrategy());
}
}

/**
Expand Down
10 changes: 4 additions & 6 deletions pkg/amqp-bunny/Tests/AmqpConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Enqueue\AmqpBunny\Tests;

use Enqueue\AmqpBunny\AmqpConnectionFactory;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\PsrConnectionFactory;
use PHPUnit\Framework\TestCase;
Expand All @@ -16,13 +17,10 @@ public function testShouldImplementConnectionFactoryInterface()
$this->assertClassImplements(PsrConnectionFactory::class, AmqpConnectionFactory::class);
}

public function testShouldSupportAmqpLibScheme()
public function testShouldSetRabbitMqDlxDelayStrategyIfRabbitMqSchemeExtensionPresent()
{
// no exception here
new AmqpConnectionFactory('amqp+bunny:');
$factory = new AmqpConnectionFactory('amqp+rabbitmq:');

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The given DSN scheme "amqp+foo" is not supported. Could be one of "amqp", "amqps", "amqp+bunny" only.');
new AmqpConnectionFactory('amqp+foo:');
$this->assertAttributeInstanceOf(RabbitMqDlxDelayStrategy::class, 'delayStrategy', $factory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @group functional
*/
class AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest extends SendToTopicAndReceiveFromQueueSpec
class AmqpSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec
{
/**
* {@inheritdoc}
Expand Down

This file was deleted.

5 changes: 5 additions & 0 deletions pkg/amqp-ext/AmqpConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Enqueue\AmqpTools\ConnectionConfig;
use Enqueue\AmqpTools\DelayStrategyAware;
use Enqueue\AmqpTools\DelayStrategyAwareTrait;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
use Interop\Queue\PsrContext;

Expand Down Expand Up @@ -34,6 +35,10 @@ public function __construct($config = 'amqp:')
->addSupportedScheme('amqps+ext')
->parse()
;

if (in_array('rabbitmq', $this->config->getSchemeExtensions(), true)) {
$this->setDelayStrategy(new RabbitMqDlxDelayStrategy());
}
}

/**
Expand Down
11 changes: 4 additions & 7 deletions pkg/amqp-ext/Tests/AmqpConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Enqueue\AmqpExt\AmqpConnectionFactory;
use Enqueue\AmqpExt\AmqpContext;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\PsrConnectionFactory;
use PHPUnit\Framework\TestCase;
Expand All @@ -17,15 +18,11 @@ public function testShouldImplementConnectionFactoryInterface()
$this->assertClassImplements(PsrConnectionFactory::class, AmqpConnectionFactory::class);
}

public function testShouldSupportAmqpExtScheme()
public function testShouldSetRabbitMqDlxDelayStrategyIfRabbitMqSchemeExtensionPresent()
{
// no exception here
new AmqpConnectionFactory('amqp+ext:');
new AmqpConnectionFactory('amqps+ext:');
$factory = new AmqpConnectionFactory('amqp+rabbitmq:');

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The given DSN scheme "amqp+foo" is not supported. Could be one of "amqp", "amqps", "amqp+ext", "amqps+ext" only.');
new AmqpConnectionFactory('amqp+foo:');
$this->assertAttributeInstanceOf(RabbitMqDlxDelayStrategy::class, 'delayStrategy', $factory);
}

public function testShouldCreateLazyContext()
Expand Down
5 changes: 5 additions & 0 deletions pkg/amqp-lib/AmqpConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Enqueue\AmqpTools\ConnectionConfig;
use Enqueue\AmqpTools\DelayStrategyAware;
use Enqueue\AmqpTools\DelayStrategyAwareTrait;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
use Interop\Queue\PsrContext;
use PhpAmqpLib\Connection\AbstractConnection;
Expand Down Expand Up @@ -48,6 +49,10 @@ public function __construct($config = 'amqp:')
->addDefaultOption('keepalive', false)
->parse()
;

if (in_array('rabbitmq', $this->config->getSchemeExtensions(), true)) {
$this->setDelayStrategy(new RabbitMqDlxDelayStrategy());
}
}

/**
Expand Down
11 changes: 4 additions & 7 deletions pkg/amqp-lib/Tests/AmqpConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Enqueue\AmqpLib\Tests;

use Enqueue\AmqpLib\AmqpConnectionFactory;
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\PsrConnectionFactory;
use PHPUnit\Framework\TestCase;
Expand All @@ -16,14 +17,10 @@ public function testShouldImplementConnectionFactoryInterface()
$this->assertClassImplements(PsrConnectionFactory::class, AmqpConnectionFactory::class);
}

public function testShouldSupportAmqpLibScheme()
public function testShouldSetRabbitMqDlxDelayStrategyIfRabbitMqSchemeExtensionPresent()
{
// no exception here
new AmqpConnectionFactory('amqp+lib:');
new AmqpConnectionFactory('amqps+lib:');
$factory = new AmqpConnectionFactory('amqp+rabbitmq:');

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The given DSN scheme "amqp+foo" is not supported. Could be one of "amqp", "amqps", "amqp+lib');
new AmqpConnectionFactory('amqp+foo:');
$this->assertAttributeInstanceOf(RabbitMqDlxDelayStrategy::class, 'delayStrategy', $factory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @group functional
*/
class AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest extends SendToTopicAndReceiveFromQueueSpec
class AmqpSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec
{
/**
* {@inheritdoc}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/receive.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

$connection = new AmqpConnectionFactory($config);
Expand Down
1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/receive_logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

$connection = new AmqpConnectionFactory($config);
Expand Down
1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/receive_logs_direct.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

$connection = new AmqpConnectionFactory($config);
Expand Down
1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/receive_logs_topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

$connection = new AmqpConnectionFactory($config);
Expand Down
1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/rpc_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

class FibonacciRpcClient
Expand Down
1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/rpc_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

function fib($n)
Expand Down
1 change: 0 additions & 1 deletion pkg/amqp-lib/tutorial/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
'receive_method' => 'basic_consume',
];

$connection = new AmqpConnectionFactory($config);
Expand Down
Loading

0 comments on commit b9c49c6

Please sign in to comment.