Adapt the package to the yiisoft/queue changes#124
Conversation
viktorprogger
commented
May 10, 2026
| Q | A |
|---|---|
| Is bugfix? | ✔️ |
| New feature? | ❌ |
| Breaks BC? | ✔️ |
| Fixed issues | ❌ |
|
Bench fails are ok since the |
eb7dd67 to
d0f31bc
Compare
|
Benchmarks still use old API. |
| ->withAutoDelete(true) | ||
| ->withType(AMQPExchangeType::TOPIC); | ||
|
|
||
| $deliveryTime = time() + (int) $delaySeconds; |
There was a problem hiding this comment.
The fractional part is truncated and then used in the DLX queue name. x-expires and x-message-ttl are not truncated.
For example, delays 1.1 and 1.9 pushed in the same second both declare queue.dlx.<now+1>, but with TTLs 1100 and 1900. RabbitMQ will reject the second declaration with an inequivalent-args/precondition failure.
Either we should keep milliseconds for queue names or keep TTLs in sync in this case.
There was a problem hiding this comment.
Pull request overview
Updates this AMQP adapter and its test suite to align with recent yiisoft/queue API changes (middleware factories/config, queue provider APIs, status semantics), including a shift from the package-specific delay middleware to the core DelayEnvelope mechanism.
Changes:
- Refactors test bootstrap and unit/integration tests to the new middleware factory/config and queue provider APIs.
- Renames “channel” concepts to “queue” (
withChannelName()→withQueueName(), default queue constant updates). - Replaces
DelayMiddlewarewith delayed push support in the AMQPAdapterdriven byDelayEnvelope.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/yii | Updates CLI test app wiring for new middleware factories/config and predefined queue provider. |
| tests/Unit/UnitTestCase.php | Adapts unit test scaffolding to new Queue/Worker constructor signatures and push middleware config. |
| tests/Unit/QueueTest.php | Updates expectations for new status/exception semantics and queue naming API. |
| tests/Unit/QueueSettingsTest.php | Adds pre-test cleanup for multiple queue/exchange names and updates queue creation flow. |
| tests/Unit/QueueProviderTest.php | Updates queue creation and queue naming API usage. |
| tests/Unit/DelayMiddlewareTest.php | Removes unit tests for deleted DelayMiddleware. |
| tests/Support/FakeAdapter.php | Updates adapter status return type to MessageStatus. |
| tests/Integration/TestCase.php | Updates queue listener invocation to new CLI argument format. |
| tests/Integration/DelayMiddlewareTest.php | Switches delay behavior testing to DelayEnvelope and validates “no exchange” error case. |
| src/Settings/Queue.php | Updates default queue name constant to the new core queue provider default. |
| src/QueueProviderInterface.php | Renames withChannelName() to withQueueName(). |
| src/QueueProvider.php | Implements withQueueName() and adjusts internal variable naming accordingly. |
| src/Middleware/DelayMiddleware.php | Removes the package-specific delay middleware implementation. |
| src/Adapter.php | Implements delayed publish logic via DelayEnvelope, updates status() behavior, and removes withChannel(). |
Comments suppressed due to low confidence (2)
src/Adapter.php:55
- Adapter::push() caches an AMQPMessage initialized with
$this->queueProvider->getMessageProperties(). If an Adapter instance is cloned via withQueueProvider() (or otherwise has its QueueProvider changed) and the new provider has different message properties, the cached AMQPMessage will still carry the old properties. Consider resetting$this->amqpMessagewhen changing the QueueProvider (e.g. inside withQueueProvider()) or building the AMQPMessage per push to avoid stale properties.
$this->amqpMessage ??= new AMQPMessage(
'',
$this->queueProvider->getMessageProperties(),
);
$amqpMessage = $this->amqpMessage;
tests/Unit/QueueTest.php:96
- In this test,
expectExceptionMessage()is called after$queue->listen(). Since the exception is thrown bylisten(), the message expectation line is never executed, so the exception message is not actually asserted. MoveexpectExceptionMessage((string) $time)before calling$queue->listen().
$this->expectException(MessageFailureException::class);
$queue->listen();
$this->expectExceptionMessage((string)$time);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $deliveryTime = time() + (int) $delaySeconds; | ||
| $queueSettings = $this->queueProvider->getQueueSettings(); | ||
| $dlxQueueSettings = $queueSettings | ||
| ->withName("{$queueSettings->getName()}.dlx.$deliveryTime") | ||
| ->withAutoDeletable(true) | ||
| ->withArguments([ | ||
| 'x-dead-letter-exchange' => ['S', $exchangeSettings->getName()], | ||
| 'x-expires' => ['I', (int) ($delaySeconds * 1000) + 30000], | ||
| 'x-message-ttl' => ['I', (int) ($delaySeconds * 1000)], | ||
| ]); | ||
|
|
||
| $messageProperties = array_merge( | ||
| $this->queueProvider->getMessageProperties(), | ||
| [ | ||
| 'expiration' => (int) ($delaySeconds * 1000), |
| $dlxQueueProvider | ||
| ->getChannel() | ||
| ->basic_publish( | ||
| $amqpMessage, | ||
| $dlxExchangeSettings->getName(), | ||
| '', | ||
| ); |