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

[amqp] Set delay strategy if rabbitmq scheme extension present. #536

Merged
merged 2 commits into from
Sep 17, 2018
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
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