Skip to content

Commit 63cda2d

Browse files
committed
[amqp] Set delay strategy if rabbitmq scheme extension present.
1 parent 78051c9 commit 63cda2d

11 files changed

+10
-86
lines changed

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
/**

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
}

Tests/Spec/AmqpSendToTopicAndReceiveFromQueueWithBasicGetMethodTest.php 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}

Tests/Spec/AmqpSendToTopicAndReceiveFromQueueWithBasicConsumeMethodTest.php

-71
This file was deleted.

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);

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);

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);

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);

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

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)

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)