jtl/nachricht

Nachricht is a distributed event queue system

0.13.0 2020-12-17 16:49 UTC

README

Testing

Nachricht

Nachricht is an message dispatcher which focuses on distributing workloads.

Features

  • Directly dispatch messages
  • Dispatch messages via AMQP
  • auto-discovery to find and create AMQP Messages queues
  • dead-lettering mechanism

Requirements

A PSR-11 compatible container (we recommend the Symfony DependencyInjection component) is required. The instances of listeners will be obtained from the container via $container->get($listenerClass).

Usage

Create an message class by implementing JTL\Nachricht\Contract\Message\Message.

use JTL\Nachricht\Contract\Message\Message;

class DummyMessage implements Message
{
    private string $data;

    public function __construct(string $data)
    {
        $this->data = $data;
    }

    public function getData(): string
    {
        return $this->data;
    }
}

Create a listener class by implementing JTL\Nachricht\Contract\Listener\Listener

use JTL\Nachricht\Contract\Listener\Listener;

class DummyListener implements Listener
{
    public function listen(DummyMessage $event): void
    {
        echo 'Dummy Listener called: ' . $event->getData() . "\n";
    }
}

Emit the Event

$emitter = $container->get(DirectEmitter::class);

$event = new FooMessage('Test');

$emitter->emit($event); 

Output

# php examples/DirectEmit/DirectEmit.php
FooListener called: Test 

You can find more examples in the example directory.