sailantis / azera-queue
Queue companion for the Azera framework: async backends (database, Redis, AMQP), a long-running worker, failed-job storage, a CLI task, and a job dispatcher.
Requires
- php: >=8.2
- psr/event-dispatcher: ^1.0
- psr/log: ^3.0
- sailantis/azera-framework: ^0.4.1 || dev-main
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
- ext-amqp: For the AmqpQueue backend.
- ext-pdo: For the DatabaseQueue backend (ships with the framework).
- ext-redis: For the RedisQueue backend (\Azera\Queue\Backend\RedisQueue).
- opis/closure: For serializing closure-based jobs.
- php-amqplib/php-amqplib: Alternative AMQP backend (no ext-amqp required).
Provides
None
Conflicts
None
Replaces
None
README
Queue companion for the Azera framework.
The framework ships queue contracts (Azera\Queue\QueueInterface, JobInterface, Job, SyncQueue, QueueException) and the docs defer async backends to a companion. This package provides:
Azera\Queue\Serialization\JobSerializerInterface+NativeSerializer— serialize/deserialize jobs for async backends, with a class-allowlist for safety.Azera\Queue\Backend\DatabaseQueue— a SQL-backed backend using the framework'sDatabase/Query(no extra extension required). Default for apps already on MySQL.Azera\Queue\Backend\RedisQueue—ext-redis-backed queue with at-least-once delivery, visibility timeouts, delayed jobs, priorities.Azera\Queue\Backend\AmqpQueue— RabbitMQ queue that works with eitherext-amqp(PECL extension) orphp-amqplib(pure-PHP library), via a transport adapter. UseAmqpQueue::wire($connection)to auto-detect the installed implementation.Azera\Queue\Backend\FileQueue— a JSON-file-backed backend needing nothing beyond core PHP. Ideal for development, single-instance deployments and cron-driven workers; jobs persist across restarts.Azera\Queue\Worker\Worker— long-running pop → deserialize →handle()→ ack loop honoringtries(),backoff(),retryUntil().Azera\Queue\Task\QueueTask—azera queue:work|failed|retry|flushCLI task extending the framework'sAzera\Cli\Task.Azera\Queue\FailedJob\FailedJobProviderInterface+ DB/Redis implementations — persist permanently failed jobs for replay.Azera\Queue\Dispatch\Dispatcher— fluentdispatch($job)->onQueue()->delay()->priority().Azera\Queue\Event\QueueEvents— PSR-14JobPushed,JobReserved,JobProcessed,JobFailed,JobRetried,JobReleased.
Installation
composer require sailantis/azera-queue
Database queue schema
CREATE TABLE azera_jobs ( id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, queue VARCHAR(64) NOT NULL, payload LONGTEXT NOT NULL, attempts INT UNSIGNED NOT NULL DEFAULT 0, available_at BIGINT UNSIGNED NOT NULL, reserved_at BIGINT UNSIGNED NULL, created_at BIGINT UNSIGNED NOT NULL, dedup_key VARCHAR(255) NULL ); CREATE INDEX idx_azera_jobs_queue_reserved ON azera_jobs (queue, reserved_at);
See src/Backend/migrations/ for the full migration.
File queue
FileQueue stores jobs as a single JSON document under a directory you supply, plus an advisory lock file. It needs no database or extension, so it's handy for shared hosting, single-instance apps and cron-driven workers.
use Azera\Queue\Backend\FileQueue; $queue = new FileQueue(__DIR__ . '/storage/queue');
Mutations run under an exclusive flock() and are written atomically (temp file + rename), so several worker processes on the same host are safe. It is not designed for concurrent writers on a shared network filesystem, nor for horizontal scale-out — reach for DatabaseQueue/RedisQueue/AmqpQueue there.
License
MIT.
MIT.