Download the PHP package pablicio/mirabel-rabbitmq without Composer
On this page you can find all versions of the php package pablicio/mirabel-rabbitmq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pablicio/mirabel-rabbitmq
More information about pablicio/mirabel-rabbitmq
Files in pablicio/mirabel-rabbitmq
Package mirabel-rabbitmq
Short Description Library to facilitate the use of rabbitmq within php based on the php-amqplib library, bringing an abstraction of its use to make its use more simplified.
License GPL-3.0-or-later
Informations about the package mirabel-rabbitmq
Mirabel RabbitMQ
Framework-agnostic RabbitMQ primitives for PHP 8.2+, built on
php-amqplib/php-amqplib — the
mature, battle-tested AMQP client created by Vadim Zaliva and Alvaro Videla and
kept alive by its community; it is the client the official RabbitMQ PHP
tutorials use. Mirabel does not replace it: it stands on it and packages the
decisions every service ends up repeating (topology, retries, error queues,
envelopes) behind one class per event, one class per worker and one verb to use
each: publish() and subscribe().
Documentação completa (pt-BR): docs/README.md · Changes: CHANGELOG.md
Install
The core reads its connection lazily from the process environment:
Publish
The constant is optional: without it the routing key comes from the class name
(OrderReceived → order.received, PedidoPagoEvent → pedido.pago).
OrderReceived::routingKey() shows what was resolved.
With MB_RABBITMQ_PUBLISHER_CONFIRMS=true, publish() returns only after the
broker has accepted the message, and throws PublishNotConfirmedException when
it refuses it. Transport failures are retried a bounded number of times
(MB_RABBITMQ_PUBLISH_RETRIES) with the same message_id.
Consume
Every constant is optional. What is left out follows a convention:
| Constant | Meaning | When omitted |
|---|---|---|
QUEUE |
queue name | class name in kebab case, without Worker (ChargeOrder → charge-order) |
EVENTS |
event classes to subscribe to | — |
ROUTING_KEYS |
extra routing keys (*/# allowed) |
— |
ATTEMPTS |
deliveries before the error queue | 1 |
RETRY_DELAY |
milliseconds in the retry queue | 0 |
PREFETCH |
unacked messages per consumer | broker default |
QUEUE_TYPE |
classic or quorum |
classic |
EXCHANGE_TYPE |
exchange type | MB_RABBITMQ_EXCHANGE_TYPE |
EVENTS and ROUTING_KEYS add up. ChargeOrder::definition() returns the
queue, keys, retry and options the worker will declare.
| The handler... | The worker... |
|---|---|
| returns | acks the message |
throws, or calls $envelope->nack() |
sends it to <queue>.retry; on the last attempt, to <queue>.error |
calls $envelope->reject() |
parks it in <queue>.error right away |
| receives a body that is not JSON | parks it in <queue>.error without calling the handler |
Attempts are read from RabbitMQ's x-death header, so the count survives
worker restarts. A retried message returns only to the queue that failed, never
to other queues bound to the same routing key. Parked messages carry
x-mirabel-failure-reason, x-mirabel-attempts and x-mirabel-exception
headers.
The classic work($msg) API with const QUEUE, routing_keys, options and
retry_options, and the static properties ($routingKey, $queue,
$routingKeys, $retry, $options), are still supported. When both are
present, the uppercase constant wins.
In Laravel, package discovery registers an optional bridge: the
MB_RABBITMQ_* variables survive config:cache, the library logs to the
Laravel log, and php artisan mirabel:work EmitirNotaFiscal runs a worker. The
core does not depend on Laravel.
A worker also operates its own queues: pending(), counts(), peek(),
failed() with Envelope::failure(), reprocess($which), discard($which)
and purge(). Queues can be capped (MAX_LENGTH, OVERFLOW), events can be
MANDATORY, and the outbox and the idempotency store come ready for PDO
(PdoOutboxStore, PdoIdempotencyStore).
Delivery is at-least-once: handlers should be idempotent. A worker can plug in
an IdempotencyStoreInterface to skip messages it has already processed.
$worker->stop() (or SIGTERM/SIGINT with ext-pcntl) finishes the current
message and leaves subscribe().
Test
Disclaimer
Mirabel is a small library built for learning and for small services. Read the limitations section of the docs before putting it in front of money.