Skip to content

Commit b9c49c6

Browse files
authored
Merge pull request #536 from php-enqueue/amqp-set-delay-strategy-if-rabbitmq-scheme-extension
[amqp] Set delay strategy if rabbitmq scheme extension present.
2 parents e5dcdc5 + 3725995 commit b9c49c6

25 files changed

+182
-229
lines changed

Diff for: pkg/amqp-bunny/AmqpConnectionFactory.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Enqueue\AmqpTools\ConnectionConfig;
88
use Enqueue\AmqpTools\DelayStrategyAware;
99
use Enqueue\AmqpTools\DelayStrategyAwareTrait;
10+
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
1011
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
1112
use Interop\Queue\PsrContext;
1213

@@ -33,10 +34,13 @@ public function __construct($config = 'amqp:')
3334
{
3435
$this->config = (new ConnectionConfig($config))
3536
->addSupportedScheme('amqp+bunny')
36-
->addDefaultOption('receive_method', 'basic_get')
3737
->addDefaultOption('tcp_nodelay', null)
3838
->parse()
3939
;
40+
41+
if (in_array('rabbitmq', $this->config->getSchemeExtensions(), true)) {
42+
$this->setDelayStrategy(new RabbitMqDlxDelayStrategy());
43+
}
4044
}
4145

4246
/**

Diff for: pkg/amqp-bunny/Tests/AmqpConnectionFactoryTest.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Enqueue\AmqpBunny\Tests;
44

55
use Enqueue\AmqpBunny\AmqpConnectionFactory;
6+
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
67
use Enqueue\Test\ClassExtensionTrait;
78
use Interop\Queue\PsrConnectionFactory;
89
use PHPUnit\Framework\TestCase;
@@ -16,13 +17,10 @@ public function testShouldImplementConnectionFactoryInterface()
1617
$this->assertClassImplements(PsrConnectionFactory::class, AmqpConnectionFactory::class);
1718
}
1819

19-
public function testShouldSupportAmqpLibScheme()
20+
public function testShouldSetRabbitMqDlxDelayStrategyIfRabbitMqSchemeExtensionPresent()
2021
{
21-
// no exception here
22-
new AmqpConnectionFactory('amqp+bunny:');
22+
$factory = new AmqpConnectionFactory('amqp+rabbitmq:');
2323

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

Diff for: pkg/amqp-bunny/Tests/Spec/AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest.php renamed to pkg/amqp-bunny/Tests/Spec/AmqpSendToTopicAndReceiveFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @group functional
1414
*/
15-
class AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest extends SendToTopicAndReceiveFromQueueSpec
15+
class AmqpSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec
1616
{
1717
/**
1818
* {@inheritdoc}

Diff for: pkg/amqp-bunny/Tests/Spec/AmqpSendToTopicAndReceiveFromQueueWithBasicConsumeMethodTest.php

-61
This file was deleted.

Diff for: pkg/amqp-ext/AmqpConnectionFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Enqueue\AmqpTools\ConnectionConfig;
66
use Enqueue\AmqpTools\DelayStrategyAware;
77
use Enqueue\AmqpTools\DelayStrategyAwareTrait;
8+
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
89
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
910
use Interop\Queue\PsrContext;
1011

@@ -34,6 +35,10 @@ public function __construct($config = 'amqp:')
3435
->addSupportedScheme('amqps+ext')
3536
->parse()
3637
;
38+
39+
if (in_array('rabbitmq', $this->config->getSchemeExtensions(), true)) {
40+
$this->setDelayStrategy(new RabbitMqDlxDelayStrategy());
41+
}
3742
}
3843

3944
/**

Diff for: pkg/amqp-ext/Tests/AmqpConnectionFactoryTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Enqueue\AmqpExt\AmqpConnectionFactory;
66
use Enqueue\AmqpExt\AmqpContext;
7+
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
78
use Enqueue\Test\ClassExtensionTrait;
89
use Interop\Queue\PsrConnectionFactory;
910
use PHPUnit\Framework\TestCase;
@@ -17,15 +18,11 @@ public function testShouldImplementConnectionFactoryInterface()
1718
$this->assertClassImplements(PsrConnectionFactory::class, AmqpConnectionFactory::class);
1819
}
1920

20-
public function testShouldSupportAmqpExtScheme()
21+
public function testShouldSetRabbitMqDlxDelayStrategyIfRabbitMqSchemeExtensionPresent()
2122
{
22-
// no exception here
23-
new AmqpConnectionFactory('amqp+ext:');
24-
new AmqpConnectionFactory('amqps+ext:');
23+
$factory = new AmqpConnectionFactory('amqp+rabbitmq:');
2524

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

3128
public function testShouldCreateLazyContext()

Diff for: pkg/amqp-lib/AmqpConnectionFactory.php

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Enqueue\AmqpTools\ConnectionConfig;
88
use Enqueue\AmqpTools\DelayStrategyAware;
99
use Enqueue\AmqpTools\DelayStrategyAwareTrait;
10+
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
1011
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
1112
use Interop\Queue\PsrContext;
1213
use PhpAmqpLib\Connection\AbstractConnection;
@@ -48,6 +49,10 @@ public function __construct($config = 'amqp:')
4849
->addDefaultOption('keepalive', false)
4950
->parse()
5051
;
52+
53+
if (in_array('rabbitmq', $this->config->getSchemeExtensions(), true)) {
54+
$this->setDelayStrategy(new RabbitMqDlxDelayStrategy());
55+
}
5156
}
5257

5358
/**

Diff for: pkg/amqp-lib/Tests/AmqpConnectionFactoryTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Enqueue\AmqpLib\Tests;
44

55
use Enqueue\AmqpLib\AmqpConnectionFactory;
6+
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
67
use Enqueue\Test\ClassExtensionTrait;
78
use Interop\Queue\PsrConnectionFactory;
89
use PHPUnit\Framework\TestCase;
@@ -16,14 +17,10 @@ public function testShouldImplementConnectionFactoryInterface()
1617
$this->assertClassImplements(PsrConnectionFactory::class, AmqpConnectionFactory::class);
1718
}
1819

19-
public function testShouldSupportAmqpLibScheme()
20+
public function testShouldSetRabbitMqDlxDelayStrategyIfRabbitMqSchemeExtensionPresent()
2021
{
21-
// no exception here
22-
new AmqpConnectionFactory('amqp+lib:');
23-
new AmqpConnectionFactory('amqps+lib:');
22+
$factory = new AmqpConnectionFactory('amqp+rabbitmq:');
2423

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

Diff for: pkg/amqp-lib/Tests/Spec/AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest.php renamed to pkg/amqp-lib/Tests/Spec/AmqpSendToTopicAndReceiveFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @group functional
1414
*/
15-
class AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest extends SendToTopicAndReceiveFromQueueSpec
15+
class AmqpSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec
1616
{
1717
/**
1818
* {@inheritdoc}

Diff for: pkg/amqp-lib/Tests/Spec/AmqpSendToTopicAndReceiveFromQueueWithBasicConsumeMethodTest.php

-71
This file was deleted.

Diff for: pkg/amqp-lib/tutorial/receive.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'port' => 5672,
1111
'user' => 'guest',
1212
'pass' => 'guest',
13-
'receive_method' => 'basic_consume',
1413
];
1514

1615
$connection = new AmqpConnectionFactory($config);

Diff for: pkg/amqp-lib/tutorial/receive_logs.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'port' => 5672,
1313
'user' => 'guest',
1414
'pass' => 'guest',
15-
'receive_method' => 'basic_consume',
1615
];
1716

1817
$connection = new AmqpConnectionFactory($config);

Diff for: pkg/amqp-lib/tutorial/receive_logs_direct.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'port' => 5672,
1313
'user' => 'guest',
1414
'pass' => 'guest',
15-
'receive_method' => 'basic_consume',
1615
];
1716

1817
$connection = new AmqpConnectionFactory($config);

Diff for: pkg/amqp-lib/tutorial/receive_logs_topic.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'port' => 5672,
1313
'user' => 'guest',
1414
'pass' => 'guest',
15-
'receive_method' => 'basic_consume',
1615
];
1716

1817
$connection = new AmqpConnectionFactory($config);

Diff for: pkg/amqp-lib/tutorial/rpc_client.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
'port' => 5672,
1010
'user' => 'guest',
1111
'pass' => 'guest',
12-
'receive_method' => 'basic_consume',
1312
];
1413

1514
class FibonacciRpcClient

Diff for: pkg/amqp-lib/tutorial/rpc_server.php

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
'port' => 5672,
1010
'user' => 'guest',
1111
'pass' => 'guest',
12-
'receive_method' => 'basic_consume',
1312
];
1413

1514
function fib($n)

Diff for: pkg/amqp-lib/tutorial/worker.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
'port' => 5672,
1111
'user' => 'guest',
1212
'pass' => 'guest',
13-
'receive_method' => 'basic_consume',
1413
];
1514

1615
$connection = new AmqpConnectionFactory($config);

0 commit comments

Comments
 (0)