cloud-castle / queue
Очередь CloudCastle: диспетчер, идемпотентность, сообщения.
v1.9.0
2026-11-07 23:21 UTC
Requires
- php: >=8.1
- cloud-castle/command: ^1.5
- cloud-castle/config: ^2.1
- cloud-castle/di: ^1.0
- cloud-castle/provider: ^1.0
- cloud-castle/redis: ^1.2
- cloud-castle/uuid: ^1.0
- psr/log: ^3.0
Requires (Dev)
- deptrac/deptrac: ^3.0 || ^4.0
- ergebnis/composer-normalize: ^2.45
- friendsofphp/php-cs-fixer: ^3.75
- icanhazstring/composer-unused: ^0.9
- infection/infection: ^0.29 || ^0.33
- php-parallel-lint/php-parallel-lint: ^1.4
- phpmd/phpmd: ^2.15
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^1.12 || ^2.1
- phpstan/phpstan-deprecation-rules: ^1.2 || ^2.0
- phpstan/phpstan-phpunit: ^1.4 || ^2.0
- phpstan/phpstan-strict-rules: ^1.6 || ^2.0
- phpunit/phpunit: ^10.5 || ^11.5
- psalm/plugin-phpunit: ^0.19 || ^0.20
- rector/rector: ^1.2 || ^2.0
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.12 || ^4.0
- vimeo/psalm: ^6.0
- webmozart/assert: ^1.11
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano
CloudCastle Queue
Transactional outbox, идемпотентный диспетчер и CLI-воркер для PHP 8.1+ (CloudCastle).
Установка
composer require cloud-castle/queue
Требуется PHP 8.1+. Продюсер брокера (например cloud-castle/kafka) и хранилище outbox (например cloud-castle/orm → ModelOutboxStore) подключаются приложением.
Быстрый старт
<?php
use CloudCastle\DI\Container;
use CloudCastle\Provider\ProviderKernel;
use CloudCastle\Queue\Cli\WorkerLoop;
use CloudCastle\Queue\MessageHandlerInterface;
use CloudCastle\Queue\Outbox\OutboxStoreInterface;
use CloudCastle\Queue\QueueDispatcher;
use CloudCastle\Queue\QueueMessage;
use CloudCastle\Queue\QueueProducerInterface;
use CloudCastle\Queue\QueueServiceProvider;
$container = new Container();
// Config, Redis, Logger, OutboxStoreInterface, QueueProducerInterface — заранее в DI
$kernel = new ProviderKernel($container);
$kernel->register(new QueueServiceProvider());
$kernel->boot();
/** @var QueueDispatcher $dispatcher */
$dispatcher = $container->get(QueueDispatcher::class);
$dispatcher->register(new class implements MessageHandlerInterface {
public function event(): string
{
return 'home.visited';
}
public function handle(QueueMessage $message): void
{
// доменная обработка
}
});
/** @var WorkerLoop $loop */
$loop = $container->get(WorkerLoop::class);
$loop->runUntilSignal(
static function (callable $shouldStop) use ($dispatcher): void {
while (!$shouldStop()) {
// consumer->consumeOne($dispatcher) …
}
},
label: 'queue-worker',
);
Публикация через outbox:
use CloudCastle\Queue\Outbox\OutboxAwareProducer;
use CloudCastle\Queue\QueueMessage;
$producer = $container->get(OutboxAwareProducer::class);
$producer->publish(new QueueMessage(
id: $uuid,
event: 'home.visited',
payload: ['path' => '/'],
));
Возможности
- Transactional outbox —
OutboxStoreInterface,OutboxPublisher,OutboxAwareProducer,OutboxRelay/OutboxRelayLoop - Идемпотентный диспетчер —
QueueDispatcher+ RedisIdempotencyStore(без дублей, retry, DLQ) - Контракты —
QueueMessage,QueueProducerInterface,MessageHandlerInterface,DispatchResult - CLI —
WorkerLoop+SignalStopFlag(SIGTERM/SIGINT) - DI —
QueueServiceProvider(cloud-castle/provider)
Разработка
composer install
composer check # линтеры + статический анализ + тесты
composer fix # автоисправления (Rector, PHP CS Fixer, PHPCBF)
composer ci # полный CI-пайплайн локально
Полный список команд с описаниями: composer run-script --list.
Документация
- Репозиторий: https://gitverse.ru/cloud-castle/queue
- История изменений: CHANGELOG.md
- Как внести вклад: CONTRIBUTING.md
- Кодекс поведения: CODE_OF_CONDUCT.md
- Политика безопасности: SECURITY.md
Лицензия
MIT © CloudCastle (alex-4-17@yandex.ru)
🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano