lecorp / lenats
The LeNats is a Symfony bundle. it's implements event-based architecture with nats streaming on php
Installs: 111
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Type:symfony-bundle
Requires
- php: ^7.1.3
- ext-ctype: *
- ext-iconv: *
- ext-json: *
- clue/block-react: ^1.3
- google/protobuf: ^3.7
- illuminate/support: ^5.8
- ircmaxell/random-lib: ^1.2
- jms/serializer-bundle: ^2.4|^3.3
- mhujer/jms-serializer-uuid: ^1.0|^3.1
- psr/event-dispatcher: ^0.6|^1.0
- rakit/validation: ^1.1
- react/promise-timer: ^1.5
- react/socket: ^1.2
- react/stream: ^1.1
- symfony/console: ^3.4|^4.2
- symfony/event-dispatcher: ^3.4|^4.2
- symfony/framework-bundle: ^3.4|^4.2
- symfony/yaml: ^3.4|^4.2
Requires (Dev)
- phpstan/phpstan: ^0.11.2
- phpstan/phpstan-symfony: ^0.11.1
- symfony/phpunit-bridge: ^3.4|^4.2
- symplify/easy-coding-standard: ^5.4
This package is auto-updated.
Last update: 2022-02-01 13:16:38 UTC
README
Event-driven NATS streaming Symfony 4 bundle with Cloud Event standard
Install
composer require lecorp/lentas
Configuration
In 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
Workflow
Publishing
<?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);
Subscribing
bin/console nats:subscribe some.event.type -t 10
Make sure the Listener of your Event Type exists