jtl/nachricht 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jtl/nachricht

最新稳定版本:0.19.6

Composer 安装命令:

composer require jtl/nachricht

包简介

Nachricht is a distributed event queue system

README 文档

README

Testing

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.

统计信息

  • 总下载量: 33.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-04