Guide

Events & Queue

In-process events, queued messages, and CLI workers.

Use events for in-process reactions

Use EventDispatcherInterface when one application action needs to notify listeners in the same runtime.

example.php
use Lemonade\Framework\Event\EventDispatcherInterface;

final class PublishArticle
{
    public function __construct(
        private readonly EventDispatcherInterface $events,
    ) {}

    public function handle(int $articleId): void
    {
        $this->events->dispatch(new ArticlePublishedEvent($articleId));
    }
}

Queue messages for follow-up work

Use QueueBusInterface when work can continue outside the current request. Keep queue messages small and explicit.

example.php
$this->queue->dispatch(
    message: new PublishArticleMessage($articleId),
    transport: 'database',
    queue: 'default',
    delaySeconds: 0,
);

Run workers from the CLI

Queue worker operations belong to the CLI. Use framework commands to install storage and run workers over the selected transport.

example.php
vendor/bin/lemonade queue:install
vendor/bin/lemonade queue:work default database