Skip to main content
Version: 2.5.0
NATS Trigger Node interface

NATS trigger node

NATS Trigger Node

Overview

The NATS Trigger Node automatically initiates MaestroHub pipelines when messages arrive on subscribed NATS subjects. Unlike the NATS Publish connector node which sends messages from inside a running pipeline, the NATS Trigger starts new pipeline executions in response to incoming messages — enabling fully event-driven automation across core NATS and JetStream deployments.


Core Functionality

What It Does

NATS Trigger enables real-time, event-driven pipeline execution by:

1. Event-Driven Pipeline Execution Start pipelines automatically when NATS messages arrive on the subscribed subject, without manual intervention or polling. Sub-millisecond core NATS pub/sub keeps latency low.

2. Automatic Subscription Management The connector's subscription manager attaches and tears down subjects automatically as pipelines are enabled, disabled, or updated — no manual subscription bookkeeping.

3. Queue Group Load Balancing (Core NATS) When the underlying Subscribe function uses a queue group, NATS distributes messages across all consumers in the group. Run the same pipeline on multiple replicas to scale horizontally.

4. JetStream Durable Consumers When the Subscribe function enables JetStream, the trigger uses a server-tracked durable consumer with explicit ack. Messages survive broker restarts and the consumer resumes from the last acked sequence on reconnect.

5. Message Payload and Metadata Passthrough Incoming payloads and metadata (subject, queueGroup, jetstream flag, headers, replyTo) are passed to downstream nodes via the $trigger variable.


Reconnection Handling

MaestroHub automatically recovers from connection disruptions to keep message delivery reliable.

Automatic Recovery

When a NATS connection is lost and restored:

  1. Connection Lost: nats.go detects the disconnect and notifies the supervisor
  2. Reconnect Loop: The client attempts to reconnect to the next server in the URL list, with the configured Reconnect Wait backoff
  3. Subscriptions Restored: Core NATS subscriptions are re-established immediately on reconnect. JetStream durable consumers resume from their last acked sequence on the server side — no client-side state needed
  4. Transparent Recovery: Pipelines continue to receive messages once the connection is restored

What This Means for Your Workflows

ScenarioBehaviour
Brief network interruptionAutomatic resubscription within seconds; core NATS messages sent during the gap are lost
Single server failure (clustered NATS)Client transparently fails over to another seed URL
Broker restartSubscriptions automatically restored when the broker is back
JetStream durable consumerServer tracks consumer progress; on reconnect the consumer resumes from the last unacked message — no replay or duplication
MaestroHub restartAll triggers for enabled pipelines are restored on startup
Choose JetStream for at-least-once delivery

Core NATS is at-most-once: messages published during a consumer outage are not buffered. Enable JetStream on both the connection and the Subscribe function when message loss is unacceptable. JetStream streams must be provisioned out of band (NATS CLI / operator); the connector consumes from existing streams.


Configuration Options

Basic Information

FieldTypeDescription
Node LabelString (Required)Display name for the node on the pipeline canvas
DescriptionString (Optional)Explains what this trigger initiates

Parameters

ParameterTypeDefaultRequiredConstraintsDescription
Connection IDstring""Yes--NATS connection profile to use.
Function IDstring""Yes--Subscribe function within the connection. Only Subscribe functions are listed.
Trigger Modeselect"always"Noalways / onChangealways: Trigger on every message. onChange: Only trigger when payload differs from the previously received payload on the same subject.
EnabledbooleantrueNo--Enable/disable the trigger. When disabled, the subscription is not opened.
Dedup Max Keysnumber1000If onChange1–10,000Maximum distinct subjects tracked for change detection. LRU eviction beyond the limit.
Dedup TTLselect--If onChange1h / 6h / 12h / 24h / 72h / 168hPersistent dedup state TTL via JetStream. Enterprise only. Lite keeps dedup state in-memory and resets on restart.
Function Requirement

The selected function must be a NATS Subscribe function. Publish and Request functions cannot drive a trigger node.

onChange dedup scope is per-subject

The trigger hashes the payload per subject — distinct subjects each get their own onChange slot. A ((tenant)) placeholder in the Subscribe function's subject (resulting in subjects like events.acme, events.globex) gives each tenant independent change tracking.


Settings

Description

A free-text area for documenting the node's purpose and behavior. Notes here are saved with the pipeline and visible to all team members.

Execution Settings

SettingOptionsDefaultDescription
Timeout (seconds)numberPipeline defaultMaximum execution time for this node (1–600). Leave empty for pipeline default.
Retry on TimeoutPipeline Default / Enabled / DisabledPipeline DefaultWhether to retry the node if it times out.
Retry on FailPipeline Default / Enabled / DisabledPipeline DefaultWhether to retry on failure. When Enabled, shows Advanced Retry Configuration.
On ErrorPipeline Default / Stop Pipeline / Continue ExecutionPipeline DefaultBehavior when the node fails after all retries.

Advanced Retry Configuration (visible when Retry on Fail = Enabled)

FieldTypeDefaultRangeDescription
Max Attemptsnumber31–10Maximum retry attempts.
Initial Delay (ms)number1000100–30,000Wait before first retry.
Max Delay (ms)number1200001,000–300,000Upper bound for backoff delay.
Multipliernumber2.01.0–5.0Exponential backoff multiplier.
Jitter Factornumber0.10–0.5Random jitter (+-percentage).

Output Data Structure

When a NATS message triggers pipeline execution, the following data is available to downstream nodes via the $trigger variable.

Output Format

{
"_metadata": {
"type": "nats_trigger",
"connection_id": "bf29be94-fc0a-4dc4-8e5c-092f1b74eb4b",
"function_id": "aef374c3-aa2b-454e-aabc-5657faac5950",
"subject": "orders.created.acme",
"queueGroup": "order-workers",
"jetstream": false,
"contentType": "application/json",
"timestamp": "2026-05-11T17:30:00Z"
},
"payload": {
"orderId": "ORD-12345",
"customer": "acme",
"amount": 99.99
}
}

For JetStream-backed subscribes, _metadata.jetstream is true and the trigger fires only after the subscription manager observes the message. The connector handles the explicit ack on your behalf once downstream nodes complete successfully — on handler failure the message is not acked and the server redelivers it after Ack Wait.

Accessing Message Data

In downstream nodes, use the $trigger variable:

FieldExpressionDescription
Message Payload$trigger.payloadThe parsed NATS message content (JSON object or raw value)
Subject$trigger._metadata.subjectThe subject the message was delivered on (resolves wildcards)
Queue Group$trigger._metadata.queueGroupThe queue group the consumer belongs to (empty for fanout subscriptions)
JetStream Flag$trigger._metadata.jetstreamtrue when the subscription is a JetStream durable consumer
Reply Subject$trigger._metadata.replyToReply-to subject set by the sender (present only for request/reply senders)
Connection ID$trigger._metadata.connection_idThe NATS connection profile used
Function ID$trigger._metadata.function_idThe NATS Subscribe function that received the message
Trigger Type$trigger._metadata.typeAlways nats_trigger
Timestamp$trigger._metadata.timestampWhen the message was received
Custom Headers$trigger._metadata["header.X-My-Key"]Headers from the NATS message, prefixed with header.
Accessing Nested Payload Data

If your NATS messages contain JSON, access nested fields directly:

  • $trigger.payload.orderId — Access a specific field
  • $trigger.payload — Access the entire message object

Validation Rules

The NATS Trigger Node enforces these validation requirements:

Parameter Validation

Connection ID

  • Must be provided and non-empty
  • Must reference a valid NATS connection profile
  • Error: "Connection is required"

Function ID

  • Must be provided and non-empty
  • Must reference a valid NATS Subscribe function
  • Function must belong to the specified connection
  • Error: "Subscribe Function is required"

Enabled Flag

  • Must be a boolean if provided
  • Error: "Enabled must be a boolean value"

Usage Examples

Edge-to-Cloud Telemetry Bridge

Scenario: Ingest sensor readings published to NATS by edge devices and forward to a cloud time-series database.

Configuration:

  • Label: Edge Telemetry Ingest
  • Connection: Production NATS Cluster
  • Function: Subscribe to sensors.> with queue group telemetry-ingest
  • Trigger Mode: always
  • Enabled: true

Downstream Processing:

  • Parse JSON payload to extract sensor ID, value, and timestamp
  • Normalize units via a Set node
  • Write to InfluxDB
  • Optionally fan out to alerting on threshold breach

JetStream Order Processing

Scenario: Process orders published to a JetStream stream with at-least-once delivery and automatic redelivery on no-ack.

Configuration:

  • Label: Order Processor
  • Connection: Production NATS (JetStream enabled)
  • Function: Subscribe to orders.created.> with durable pipeline-order-processor, max in-flight 10
  • Trigger Mode: always
  • Enabled: true

Downstream Processing:

  • Validate the order schema
  • Check inventory via a Postgres query
  • Charge payment via a REST node
  • On success, publish orders.fulfilled (NATS Publish node) — the durable consumer acks automatically
  • On failure, the message is redelivered after Ack Wait

Per-Tenant Change Detection

Scenario: Process device-state updates from a multi-tenant subject hierarchy but only fire the pipeline when the state actually changes for that tenant.

Configuration:

  • Label: Tenant State Watcher
  • Connection: SaaS NATS Cluster
  • Function: Subscribe to tenants.*.device-state (queue group state-watcher)
  • Trigger Mode: onChange
  • Dedup Max Keys: 5000
  • Enabled: true

Downstream Processing:

  • Extract tenant and device fields from $trigger._metadata.subject
  • Update tenant-scoped state in MongoDB
  • Notify the tenant's webhook on critical transitions

Best Practices

Connection Health Monitoring

  • Set Ping Interval on the connection (default 120s) low enough to detect dead routes quickly on unreliable networks, high enough to avoid bus noise on healthy ones
  • Provide multiple URLs in Server URLs so the client can fail over between cluster seeds without operator intervention
  • Monitor connection state via MaestroHub's connection health dashboard; the connector exposes reconnect counts and last-error metrics

Choosing Between Core NATS and JetStream

RequirementPick
Lowest possible latency, can tolerate occasional lossCore NATS
Telemetry, sensor data, fanout broadcastsCore NATS
Order events, audit trail, financial eventsJetStream
Must redeliver on failure / resume after restartJetStream
Consumer may be offline for minutes/hoursJetStream
You only have one consumer instanceEither, depending on loss tolerance

Designing for Reliability

PracticeRationale
Use queue groups for horizontal scalingNATS distributes messages round-robin across queue-group members
Enable JetStream + durable name for critical streamsSurvive broker restarts, automatic redelivery on no-ack
Pick a stable, descriptive durable nameServer tracks progress against this name; renaming creates a new consumer that starts from the beginning
Tune Max In-FlightHigher values increase throughput; lower values reduce blast radius when a downstream node is slow
Use onChange Trigger Mode for monitoring subjectsAvoid firing pipelines on identical heartbeat / status payloads

Error Handling Strategies

For Critical Workflows (JetStream):

  • Set On Error to stopPipeline
  • Disable retries at the trigger node; let Ack Wait redeliver the message instead
  • Watch consumer lag via the NATS server's monitoring endpoint

For Best-Effort Processing (Core NATS):

  • Set On Error to continueExecution
  • Log failed messages — they cannot be replayed
  • Use a sidecar pipeline that writes critical payloads to long-term storage independently

Performance Considerations

ScenarioRecommendation
High message rateUse queue groups across multiple pipeline replicas; raise JetStream Max In-Flight
Large payloadsNATS recommends < 1MB per message; chunk larger payloads upstream
Wildcard subscriptionsUse * (single token) when you know the depth; reserve > (multi-token) for broad fan-in scenarios
Multi-tenant fan-outSubscribe with tenants.*.events rather than separate subscriptions per tenant

Enable vs. Disable

  • Use the trigger's Enabled parameter to temporarily pause message processing without changing pipeline state
  • Disable triggers during maintenance windows to prevent message processing (and, for JetStream, prevent unacked-message backlog from being delivered)
  • Document the reason for disabled triggers in the node's Description field