Skip to content

Adapt the package to the yiisoft/queue changes#124

Open
viktorprogger wants to merge 5 commits into
masterfrom
adapt-to-queue
Open

Adapt the package to the yiisoft/queue changes#124
viktorprogger wants to merge 5 commits into
masterfrom
adapt-to-queue

Conversation

@viktorprogger
Copy link
Copy Markdown
Contributor

Q A
Is bugfix? ✔️
New feature?
Breaks BC? ✔️
Fixed issues

@viktorprogger viktorprogger requested review from samdark and vjik May 10, 2026 16:17
@viktorprogger viktorprogger self-assigned this May 10, 2026
@viktorprogger viktorprogger mentioned this pull request May 10, 2026
@viktorprogger
Copy link
Copy Markdown
Contributor Author

Bench fails are ok since the master version is incompatible with yiisoft/queue.

@samdark
Copy link
Copy Markdown
Member

samdark commented May 11, 2026

Benchmarks still use old API.

Comment thread src/Adapter.php Outdated
->withAutoDelete(true)
->withType(AMQPExchangeType::TOPIC);

$deliveryTime = time() + (int) $delaySeconds;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DelayMiddleware with delayed push support in the AMQP Adapter driven by DelayEnvelope.

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->amqpMessage when 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 by listen(), the message expectation line is never executed, so the exception message is not actually asserted. Move expectExceptionMessage((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.

Comment thread src/Adapter.php Outdated
Comment on lines +85 to +99
$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),
Comment thread src/Adapter.php
Comment on lines +114 to +120
$dlxQueueProvider
->getChannel()
->basic_publish(
$amqpMessage,
$dlxExchangeSettings->getName(),
'',
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants