Skip to content

Replace Enqueue SimpleClient with internal EnqueueClient - #207

Open
skie wants to merge 1 commit into
cakephp:3.xfrom
skie:enqueue-client
Open

skie wants to merge 1 commit into
cakephp:3.xfrom
skie:enqueue-client

Conversation

@skie

@skie skie commented Nov 23, 2026

Copy link
Copy Markdown
Member

Replaces the vendored Enqueue\SimpleClient\SimpleClient with a plugin owned Cake\Queue\Client\EnqueueClient built from plain PHP arrays, while maintaining full backward compatibility with existing queue configs.

Publishing becomes observable: the client dispatches Queue.produce.success and Queue.produce.failure events and exposes the transport assigned messageId, mirroring the event set the worker side already has. QueueManager::push() now returns that messageId on success and null when a unique push is skipped as duplicate. The queue connection also gains a clientClass option, mirroring the existing processor option, so applications can extend the client per connection.

Key Features:

  • Cake\Queue\Client\EnqueueClient with the same public surface as SimpleClient (bindTopic, bindCommand, sendCommand, sendEvent, consume, plus driver, producer and consumer accessors), built without symfony/config
  • Cake\Queue\Client\EnqueueClientConfig normalizes string DSN or array configs with the same defaults the vendor client used, and rejects unknown keys and mistyped values with InvalidArgumentException instead of silently ignoring them
  • Cake\Queue\Client\EnqueuePostSendExtension observes the PostSend context so the success event carries messageId, transportDestination and transportMessage; the id is never generated locally, it is read off the message the transport accepted
  • Failure path dispatches Queue.produce.failure with the exception and rethrows, so the producer contract is preserved and no silent loss is possible
  • Per connection clientClass option plus PSR-11 container support: QueueManager::setContainer() stores the application container as the static fallback, engine() accepts a per call container override, and connection_factory_class resolves through the container when available
  • enqueue/simple-client removed from composer.json require; runtime now needs only cakephp/cakephp, psr/log and ramsey/uuid

Usage:

'Queue' => [
    'default' => [
        'url' => 'redis://localhost:6379',
        'queue' => 'default',
    ],
    'audited' => [
        'url' => 'redis://localhost:6379',
        'queue' => 'audited',
        'clientClass' => \App\Queue\AuditedClient::class,
    ],
],
$messageId = QueueManager::push(ProcessOrderJob::class, $order);

$engine = QueueManager::engine('audited');
$engine->getEventManager()->on('Queue.produce.success', function ($event) {
    $messageId = $event->getData('messageId');
});
$engine->getEventManager()->on('Queue.produce.failure', function ($event) {
    $exception = $event->getData('exception');
});

Note: existing Queue configs work without edits, and callers that ignore the push() return value are unaffected. Code type hinted against SimpleClient must switch to EnqueueClient. Direct calls on getProducer()->sendEvent() or sendCommand() bypass the produce events; only EnqueueClient::sendEvent(), EnqueueClient::sendCommand() and QueueManager::push() dispatch them.

@LordSimal

Copy link
Copy Markdown
Member

LGTM

are there any other major changes needed in the 3.x branch?
If not we should prepare a 3.x Beta/RC for this as 3.x is still Cake5 compatible.

4.x is the Cake6 Branch which will be published in February next year just like Cake6 itself.

@skie

skie commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

3.x still untagged, so such feature unbreaking changes not break the major release. Also this feature is non breaking change. 3.x stays cake5, and I will merge this feature to 4.x after it lands to 3.x. 4.x pull request already exists #203 so all will be done as fast as code lands for cake5.

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.

2 participants