NATS
Synopsis
Creates a JetStream consumer that connects to NATS servers and processes messages from specified streams and subjects. Supports authentication, TLS encryption, and multiple workers with automatic message acknowledgment.
Schema
- id: <numeric>
name: <string>
description: <string>
type: nats
tags: <string[]>
pipelines: <pipeline[]>
status: <boolean>
properties:
address: <string>
port: <numeric>
username: <string>
password: <string>
stream: <string>
consumer: <string>
subject: <string>
reuse: <boolean>
workers: <numeric>
buffer_size: <numeric>
stats_frequency: <numeric>
tls:
status: <boolean>
cert_name: <string>
key_name: <string>
Configuration
The following are the minimum requirements to define the device.
Device
Field | Required | Default | Description |
---|---|---|---|
id | Y | Unique identifier | |
name | Y | Device name | |
description | N | - | Optional description |
type | Y | Must be nats | |
tags | N | - | Optional tags |
pipelines | N | - | Optional pre-processor pipelines |
status | N | true | Enable/disable the device |
Connection
Field | Required | Default | Description |
---|---|---|---|
address | N | "0.0.0.0" | NATS server address |
port | Y | NATS server port | |
username | N | - | Authentication username |
password | N | - | Authentication password |
stream | Y | "vmetric" | JetStream stream name |
consumer | Y | "vmetric" | JetStream consumer name |
subject | Y | Subject pattern to subscribe to |
TLS
Field | Required | Default | Description |
---|---|---|---|
tls.status | N | false | Enable TLS encryption |
tls.cert_name | Y | TLS certificate file path (required if TLS enabled) | |
tls.key_name | Y | TLS private key file path (required if TLS enabled) |
The TLS certificate and key files must be placed in the service root directory.
Performance
Field | Required | Default | Description |
---|---|---|---|
reuse | N | true | Enable multi-worker mode |
workers | N | 4 | Number of worker processes when reuse enabled |
buffer_size | N | 9000 | Read buffer size in bytes |
stats_frequency | N | 300 | Statistics collection interval in seconds |
Advanced Features
The following are unique features that Director offers.
Multiple Workers
When reuse
is enabled, the collector uses multiple workers each of which maintains its own NATS consumer. Workers process messages independently, and messages are automatically acknowledged.
The worker count will be capped at the number of available CPU cores.
Messages
The collector supports a JetStream persistent message store, message acknowledgment and retry, multiple subject subscriptions, and custom message processing pipelines. It also provides security through TLS-encrypted connections and basic authentication.
Examples
The following are commonly used configuration types.
Basic
A basic consumer can be created easily.
Creating a simple NATS consumer... |
|
Secure
The consumer can connect to secure NATS servers.
Connecting with authentication and encryption... |
|
High-Volume
Performance can be enhanced for high message volumes.
Optimizing for high throughput... |
|
Subject Filters
Targeted message processing is possible:
Configuring for subject-based filtering... |
|
NATS subjects support *
and >
as wildcards for single and multiple tokens respectively.
Messages
Messages can be pre-processed based on custom criteria:
Applying custom processing to messages... |
|
Pipelines are processed sequentially, and can modify or drop messages before ingestion.