jardisadapter / messaging
A powerful, unified PHP messaging library for Redis, Kafka, and RabbitMQ with automatic serialization, consumer groups, and production-ready features
Requires
- php: >=8.2
- ext-amqp: *
- ext-pcntl: *
- ext-rdkafka: *
- ext-redis: *
- jardisport/messaging: ^1.0.0
- jardissupport/dotenv: ^1.0.0
Requires (Dev)
- phpstan/phpstan: ^2.0.4
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.11.2
This package is auto-updated.
Last update: 2026-03-06 06:41:43 UTC
README
Part of the Jardis Ecosystem — A modular DDD framework for PHP
A powerful, unified PHP messaging library that makes working with Redis, Kafka, RabbitMQ, and Database queues effortless. One API, multiple transports — configure brokers via addPublisher()/addConsumer() with factory-created instances while your business logic stays clean.
Features
- One API, Multiple Transports — Switch between Redis Streams, Apache Kafka, RabbitMQ, Database (PDO), and InMemory (for testing) with zero code changes
- Database Transport — No external broker required — uses your existing database as message queue (Transactional Outbox pattern)
- Fan-Out Support — Multiple consumer groups process the same event independently (Database and Redis Streams)
- Layered Architecture — Automatic fallback across multiple instances for high availability
- InMemory Transport — Deterministic testing without infrastructure dependencies
- Fluent API — 2-line setup, zero boilerplate
- Automatic Serialization — JSON encoding/decoding for arrays and JsonSerializable objects
- Consumer Groups — Horizontal scaling with Redis, Kafka, and Database consumer groups
- Graceful Shutdown — Clean stop on SIGTERM/SIGINT signals
- Lazy Connections — Connect only when needed, perfect for DI containers
- External Connection Support — Reuse existing connections from legacy systems
Installation
composer require jardisadapter/messaging
Transport extensions are optional — install only what you need:
| Transport | Requirement |
|---|---|
| Database (PDO) | None — PDO is built into PHP |
| Redis | ext-redis (PECL) |
| Kafka | ext-rdkafka (PECL) |
| RabbitMQ | ext-amqp (PECL) |
| InMemory | None — included for testing |
Quick Start
Database Transport (no broker required)
use JardisAdapter\Messaging\MessagePublisher; use JardisAdapter\Messaging\MessageConsumer; use JardisAdapter\Messaging\Factory\PublisherFactory; use JardisAdapter\Messaging\Factory\ConsumerFactory; $publisherFactory = new PublisherFactory(); $consumerFactory = new ConsumerFactory(); // Publishing $publisher = (new MessagePublisher()) ->addPublisher($publisherFactory->database('mysql:host=localhost;dbname=app', 'user', 'pass'), 'database'); $publisher->publish('orders', ['order_id' => 123, 'total' => 99.99]); // Consuming (Point-to-Point) $consumer = (new MessageConsumer()) ->addConsumer($consumerFactory->database('mysql:host=localhost;dbname=app', 'user', 'pass'), 'database'); $consumer->consume('orders', function (string|array $message, array $metadata): bool { echo "Processing order\n"; return true; // ACK });
Fan-Out (multiple consumer groups)
// Same event, 4 independent consumers $consumer->consume('InvoiceCreated', $emailHandler, ['group' => 'email-service']); $consumer->consume('InvoiceCreated', $pdfHandler, ['group' => 'pdf-service']); $consumer->consume('InvoiceCreated', $accountingHandler, ['group' => 'accounting']); $consumer->consume('InvoiceCreated', $auditHandler, ['group' => 'audit-log']);
Redis Transport
$publisher = (new MessagePublisher()) ->addPublisher($publisherFactory->redis('localhost'), 'redis'); $publisher->publish('orders', ['order_id' => 123, 'total' => 99.99]);
Documentation
Full documentation, examples and API reference:
jardis.io/docs/adapter/messaging
Jardis Ecosystem
This package is part of the Jardis Ecosystem — a collection of modular, high-quality PHP packages designed for Domain-Driven Design.
| Category | Packages |
|---|---|
| Core | Domain, Kernel, Data, Workflow |
| Adapter | Cache, Logger, Messaging, DbConnection |
| Support | DotEnv, DbQuery, Validation, Factory, ClassVersion |
| Tools | Builder, DbSchema |
License
This package is licensed under the PolyForm Noncommercial License 1.0.0.
For commercial use, see COMMERCIAL.md.