jtl / nachricht
Nachricht is a distributed event queue system
Installs: 14 940
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 2
Requires
- php: 8.1.* || 8.2.* || 8.3.*
- ext-json: *
- ext-pcntl: *
- jtl/php-generic-collection: ^1.0.0
- nikic/php-parser: ^4.18.0
- psr/container: ^2.0.2
- psr/event-dispatcher: ^1.0
- psr/log: ^3.0
- ramsey/uuid: ^4.7.5
- symfony/config: ^6.4.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.50.0
- mockery/mockery: ^1.6.7
- php-amqplib/php-amqplib: ^3.6.1
- phpstan/phpstan: ^1.10.59
- phpunit/phpunit: ^9.6.17
Suggests
- monolog/monolog: Required when using AmqpEmitter / Consumer
- php-amqplib/php-amqplib: Required for RabbitMq Transport
- symfony/dependency-injection: Recommended DI-Container
- symfony/yaml: Required for Symfony DI-Container and examples
- dev-master
- 0.19.4
- 0.19.3
- 0.19.2
- 0.19.1
- 0.19.0
- 0.18.0
- 0.17.3
- 0.17.2
- 0.17.1
- 0.17.0
- 0.16.1
- 0.16.0
- 0.15.0
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.5
- 0.13.4
- 0.13.3
- 0.13.2
- 0.13.1
- 0.13.0
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- 0.0.2
- 0.0.1
- dev-EA-6324
- dev-EA-6300
- dev-dependabot/composer/examples/phpseclib/phpseclib-3.0.21
- dev-dependabot/composer/phpseclib/phpseclib-3.0.21
- dev-EA-5384
- dev-log_deadletter
- dev-consumer_timeout
- dev-EA-3616
- dev-EA-4622
- dev-RemoveLog_13
- dev-UpdateGenericCollection
- dev-ExtendLog0_13
- dev-ExtendLog
- dev-ci
This package is auto-updated.
Last update: 2025-03-08 14:42:16 UTC
README
Nachricht
Nachricht is a 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)
.
The RabbitMQ delayed message exchange plugin may be installed before using Nachricht to make sure you can work with message delay.
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
Emit delayed messages
A delay can be used to make a message invisible for the consumer until a defined time is reached. There are two types of delay available
On message construct: delay a message when it is getting emitted. You can specify such a delay (in seconds) when constructing a new message instance.
$event = new DelayedDummyAmqpMessage(data: 'Test', delay: 3); $emitter->emit($event);
To specify a retry delay overwrite method getRetryDelay(): int
method (default retry delay is set to 3 seconds).
Such delay will be used every time a Listener facing an Error when cause jtl/nachricht to re-queue the message
You can find more examples in the example
directory.