becklyn/messaging

0.1.2 2021-12-03 11:24 UTC

This package is auto-updated.

Last update: 2024-11-29 06:41:13 UTC


README

becklyn/messaging provides technology independent abstractions for asynchronous messaging.

🚧 Currently only a Redis backend is available!

Installation

composer require becklyn/messaging

Getting started

Creating messages is done using a MessageBuilder. By default, there is a JSON Builder based on Symfony Serializer. Messages can be published using the Publisher:

$builder = new SymfonyJsonSerializedMessageBuilder($serializer);
$message = $builder->build("content", "destination");

$publisher = new Publisher($connection, $serializer);
$publisher->publish($message);

Consuming messages is as simple as publishing them. For this task the library offers a Consumer. Together with a Worker, Messages can be processed on delivery:

class SampleWorker implements Worker
{
    public function execute(Message $message) : void
    {
        // TODO: Process the received message ...
        \var_dump($message);
    }
}
$queue = new QueueDefinition("destination");
$params = new ConsumerParams();

$consumer = new Consumer($connection, $serializer, $lifecycleManager);
$consumer->consume(new SampleWorker(), $queue, $params);