Skip to main content

NATS

Push Pull

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

FieldRequiredDefaultDescription
idYUnique identifier
nameYDevice name
descriptionN-Optional description
typeYMust be nats
tagsN-Optional tags
pipelinesN-Optional pre-processor pipelines
statusNtrueEnable/disable the device

Connection

FieldRequiredDefaultDescription
addressN"0.0.0.0"NATS server address
portYNATS server port
usernameN-Authentication username
passwordN-Authentication password
streamY"vmetric"JetStream stream name
consumerY"vmetric"JetStream consumer name
subjectYSubject pattern to subscribe to

TLS

FieldRequiredDefaultDescription
tls.statusNfalseEnable TLS encryption
tls.cert_nameYTLS certificate file path (required if TLS enabled)
tls.key_nameYTLS private key file path (required if TLS enabled)
note

The TLS certificate and key files must be placed in the service root directory.

Performance

FieldRequiredDefaultDescription
reuseNtrueEnable multi-worker mode
workersN4Number of worker processes when reuse enabled
buffer_sizeN9000Read buffer size in bytes
stats_frequencyN300Statistics 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.

note

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...

- id: 1
name: basic_nats
type: nats
properties:
address: "nats.example.com"
port: 4222
subject: "logs.>"

Secure

The consumer can connect to secure NATS servers.

Connecting with authentication and encryption...

- id: 2
name: secure_nats
type: nats
properties:
address: "nats.example.com"
port: 4222
username: "consumer"
password: "secret"
stream: "LOGS"
consumer: "processor"
subject: "logs.secure.>"
tls:
status: true
cert_name: "nats.crt"
key_name: "nats.key"

High-Volume

Performance can be enhanced for high message volumes.

Optimizing for high throughput...

- id: 3
name: performant_nats
type: nats
properties:
address: "nats.example.com"
port: 4222
stream: "LOGS"
consumer: "high-perf"
subject: "logs.>"
reuse: true
workers: 4
buffer_size: 32768
stats_frequency: 60

Subject Filters

Targeted message processing is possible:

Configuring for subject-based filtering...

- id: 4
name: filtered_nats
type: nats
properties:
address: "nats.example.com"
port: 4222
stream: "LOGS"
consumer: "filtered"
subject: "logs.*.error"
reuse: true
workers: 2
tip

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...

- id: 5
name: pipeline_nats
type: nats
pipelines:
- json_parser
- field_extractor
properties:
address: "nats.example.com"
port: 4222
stream: "LOGS"
consumer: "processed"
subject: "logs.raw.>"
note

Pipelines are processed sequentially, and can modify or drop messages before ingestion.