Skip to main content

Dirthara Queue

Dirthara Queue hands messages to a queue and processes them later in a worker. A message is a plain PHP object: the package serialises it onto a queue, and a worker takes it off again, passes it to the handler registered for its exact class, and decides, when handling fails, whether to retry it, how long to wait first, or to fail it for good.

The package is transport-neutral. Its contracts describe a queue, a delivery, and a queue driver without assuming a database, a broker, or a network; it ships an in-memory queue that implements them, for tests and for processing within a single PHP process.

PieceDoesRead
QueuedMessagePublisherSerialises a message onto a queue, now or after a delayPublishing
MessageHandlerRegistryMaps each exact message class to the callable that processes itHandlers
MessageExecutionPolicyRegistryChooses the retry and backoff behaviour per exact message classExecution policies
Worker and WorkerRunnerProcess one delivery, or keep processing until stopped or limitedWorkers
FailedMessageRepositoryLists, retries, and forgets messages that failed for goodFailed messages
QueueDriverRegistryCreates a queue from a named driver and its configurationQueues and drivers
NativeMessageSerialiserTurns a message into a payload and backSerialisation
use Dirthara\Queue\Driver\Memory\InMemoryQueue;
use Dirthara\Queue\MessageHandlerRegistry;
use Dirthara\Queue\QueuedMessagePublisher;
use Dirthara\Queue\Serialiser\NativeMessageSerialiser;

$queue = new InMemoryQueue();
$serialiser = new NativeMessageSerialiser();

$publisher = new QueuedMessagePublisher($queue, $serialiser);
$publisher->publish(new SendWelcomeEmail('ada@example.com'));

$handlers = new MessageHandlerRegistry();
$handlers->register(SendWelcomeEmail::class, static function (SendWelcomeEmail $message) use ($mailer): void {
$mailer->sendWelcomeEmail($message->email);
});

Getting started builds this into a complete worker. See installation for the requirements, and exceptions for every failure the package reports.

The package publishes through the MessagePublisher contract of Dirthara Messaging, so code that publishes a message does not know it is queued.