Message Bus
A RabbitMQ backed message bus for publishing and consuming background work.
Message Bus wraps php-amqplib to give Raxos applications a small, typed API for pushing work onto a queue and consuming it later. Messages are plain PHP objects that implement MessageInterface and carry a Handler attribute pointing at the class that processes them, so publishing and consuming code never needs a routing table. The package supports five priority levels, persistent delivery, a per worker message limit, and a small set of typed exceptions for connection, publish, consume and timeout failures.
Highlights
MessageBusOwns the AMQP connection and creates the queues you publish to and consume from.MessageBusQueueA single queue that publishes messages and consumes them with an acknowledge callback.HandlerClass attribute that links a message to the handler that processes it.MessagePriorityFive priority levels applied to a message when you publish it.Explore by category
- Messages and handlers: define a message class, mark it with a
Handlerattribute, and write the handler that processes it. - Publishing and consuming: connect to RabbitMQ, create a queue, publish with a priority, and consume with an acknowledge callback.
Quick example
php
<?php
declare(strict_types=1);
use Raxos\MessageBus\{MessageBus, Enum\MessagePriority};
$bus = new MessageBus(
host: 'localhost',
port: 5672,
username: 'guest',
password: 'guest'
);
$queue = $bus->createQueue('task_queue');
$queue->publish(new SendWelcomeEmailMessage($userId), MessagePriority::HIGH);Installation
Install it with Composer.
shell
composer require raxos/message-busSee installation for requirements, or use the sidebar to navigate this package.