mammatus / queue
⏱️ Queue manager
Package info
Language:Makefile
Type:composer-plugin
pkg:composer/mammatus/queue
Fund package maintenance!
Requires
- php: ^8.4
- composer-plugin-api: ^2.0
- ext-json: ^8.4
- eventsauce/object-hydrator: ^1.6.1
- mammatus/app: ^0.1.0
- mammatus/groups: ^0.3.0 || ^0.4.0
- mammatus/kubernetes-attributes: ^1.1.0
- mammatus/kubernetes-contracts: ^1.1.0
- mammatus/kubernetes-events: ^5.0.0
- mammatus/life-cycle-events: ^2.3.0
- mammatus/queue-attributes: ^0.2.0
- mammatus/queue-contracts: ^0.1.0
- mammatus/terraform-events: ^0.1.1
- open-telemetry/api: ^1.11.0
- psr/container: ^1.1.2 || ^2.0.2
- psr/event-dispatcher: ^1.0
- psr/log: ^3.0.2
- queue-interop/queue-interop: ^0.8.2
- react/async: ^4.3.0
- react/event-loop: ^1.6.0
- react/promise: ^3.3.0
- react/promise-timer: ^1.11.0
- realodix/change-case: ^4.2.4
- roave/better-reflection: ^6.69.0
- wyrihaximus/broadcast-contracts: ^1.3.0
- wyrihaximus/generative-composer-plugin-tooling: ^1.9.1
- wyrihaximus/monolog-factory: ^2.1.0
- wyrihaximus/psr-3-callable-throwable-logger: ^2.4.0
- wyrihaximus/psr-3-context-logger: ^3.0.0
- wyrihaximus/ticking-promise: ^3.2.0
Requires (Dev)
- bbqueue/bunny: dev-main
- bunny/bunny: 0.6.0-alpha.4@dev
- shipmonk/dead-code-detector: ^0.14.1 || ^0.15.0 || ^1.0.0
- wyrihaximus/async-test-utilities: ^14.8.0
- wyrihaximus/makefiles: ^0.15.5
Suggests
- shipmonk/dead-code-detector: This package supports ^1 || ^0.15 || ^0.14.1 by hooking in and marking all listeners as alive
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 08:53:50 UTC
README
⏱️ Queue manager: async queue worker infrastructure with code generation.
What it does
This package has two sides:
Code generation (Composer plugin): On every composer install or composer update, the plugin scans all classes implementing Mammatus\Queue\Contracts\Worker that are annotated with #[Consumer] or #[Consumers] attributes. For each worker/method/DTO combination it generates:
- A
Consumerclass: aLifeCycleHandlerthat starts and stops the queue consumer - A
WorkerFactoryclass: factory that creates theWorkerconfiguration - A
Producerclass: serializes DTOs, encodes them, and sends them to the correct queue - A
Hydratorclass: EventSauce object hydrator for all DTOs - Kubernetes Helm
GroupAddons: adds worker add-ons to Helm values - Terraform queue list: registers queue names as Terraform variables
Runtime: The Consumer class polls queues, decodes messages, hydrates them into DTOs, and invokes the worker method. It supports concurrency, OpenTelemetry tracing, and structured logging.
Setup
Add the package and enable the plugin in composer.json:
{
"extra": {
"mammatus": {
"queue": {
"has-workers": true
}
}
}
}
The "has-workers": true flag tells the plugin to scan for workers. Without it, no code is generated.
Defining workers
Create a class implementing Mammatus\Queue\Contracts\Worker and annotate it with #[Consumer] or #[Consumers]:
use Mammatus\Queue\Attributes\Consumer; use Mammatus\Queue\Contracts\Worker; #[Consumer(friendlyName: 'my-worker', queue: 'my-queue', dtoClass: MyMessage::class, concurrency: 4)] final class MyWorker implements Worker { public function handle(MyMessage $work): void { // Process the message } }
The #[Consumer] attribute controls:
| Property | Description |
|---|---|
queue |
Queue name to consume from |
dtoClass |
The message DTO class this consumer handles |
concurrency |
Number of parallel consumers for this queue |
friendlyName |
Human-readable suffix for generated class names |
Use #[Consumers] to group multiple #[Consumer] attributes:
use Mammatus\Queue\Attributes\Consumer; use Mammatus\Queue\Attributes\Consumers; use Mammatus\Queue\Contracts\Worker; #[Consumers( new Consumer(friendlyName: 'fast', queue: 'priority', dtoClass: FastMessage::class, concurrency: 8), new Consumer(friendlyName: 'slow', queue: 'background', dtoClass: SlowMessage::class, concurrency: 2), )] final class MultiWorker implements Worker { public function process(FastMessage|SlowMessage $work): void { // Handle both message types } }
Worker methods must be public, accept exactly one parameter, and that parameter must implement Mammatus\Queue\Contracts\Work. Union types are supported, and each type in the union is matched against the dtoClass in the #[Consumer] attribute.
Defining messages
Messages are plain DTOs implementing Mammatus\Queue\Contracts\Work:
use Mammatus\Queue\Contracts\Work; final class MyMessage implements Work { public function __construct( public readonly string $id, public readonly string $payload, ) { } }
Sending messages
Use the generated Mammatus\Queue\Producer to send messages:
use Mammatus\Queue\Producer; $producer->send(new MyMessage('abc-123', 'Hello'));
The producer serializes the message, encodes it, injects OpenTelemetry trace headers, and routes it to the correct queue based on the DTO class.
Generated files
All generated files live in src/ and are regenerated on every composer install or composer update:
| File | Purpose |
|---|---|
src/Consumer/*.php |
Per-worker consumer lifecycle handlers |
src/Consumer/WorkerFactory/*.php |
Worker configuration factories |
src/Producer.php |
Message sender with queue routing |
src/Hydrator.php |
EventSauce hydrator for all DTOs |
src/Kubernetes/Helm/GroupAddons.php |
Kubernetes Helm worker add-ons |
src/Terraform/Queues.php |
Terraform queue name registry |
Do not edit these files manually; they will be overwritten on the next Composer run.
License
The MIT License (MIT)
Copyright (c) 2026 Cees-Jan Kiewiet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.