全工具/lenats

此包已被废弃且不再维护。未建议替代包。

LeNats 是一个 Symfony 扩展包。它实现了基于事件的架构,在 PHP 上使用 NATS 流。

安装次数: 4,070

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 5

公开问题: 1

类型:symfony-bundle

v0.4.18 2020-12-03 07:06 UTC

README

build coverage

基于事件的 NATS 流的 Symfony 3/4 扩展包,支持 Cloud Event 标准。

安装

composer require vseinstrumentiru/lenats

配置

config/packages/le_nats.yaml

le_nats:
  connection:
    dsn: 'tcp://your-nats/host' # Required.
    client_id: 'unique_app_client_id' # Required. A unique identifier for a client. See ConnectRequest in https://nats.io/documentation/streaming/nats-streaming-protocol/
    cluster_id: 'your_nats_cluster_id' # Required. Cluster ID from nats streaming configuration. See https://github.com/nats-io/nats-streaming-server#configuration-file
    verbose: false # Optional. by default false, if you need additional set it to true
     
    context: # Optional. if you need additional configuration for TLS or TCP (will added soon) - you can define it here
      tls:
        protocol: tlsv1.2
        ciphers: ECDHE-RSA-AES256-GCM-SHA384
        peer_name: 'connection_peer_name'
        verify_peer: false
        verify_peer_name: false
        allow_self_signed: true
        
  accept_events: # Optional.
    # If you want to accept specific Event Object for each event - you can define it here
    # Here application.test.created - event type (or name)
    # App\Events\TestCloudEvent - class for this event
    # Class App\Events\TestCloudEvent MUST inherit LeNats\Events\CloudEvent
    application.test.created: App\Events\TestCloudEvent

工作流程

发布

<?php
$publisher = $container->get(\LeNats\Subscription\Publisher::class);

$event = new \LeNats\Events\CloudEvent();
$event->setType('some.event.type.created'); // This event wil be published to some.event.type queue
// $event->setId('unique-id'); Id will gets from data['id'] field, if it exists 
$data = [
    'id' => 'unique-id',
    'value' => 'Some event value'
];
$event->setData($data);

$publisher->publish($event);

订阅

bin/console nats:subscribe some.event.type -t 10

确保您的 Event 类型存在 Listener。