NATS Endpoint
Publish and consume correlated messages over NATS subjects with optional queue groups and auth settings.
Core Fields
Configure ServerUrl, Subject, and Mode. QueueGroup is optional for consumer-side load sharing, and ConnectionName helps trace connections in broker diagnostics.
Authentication
Use UserName + Password for basic auth or Token for token-based auth. Validation blocks invalid combinations so credentials are explicit and transport-safe.
Tracking Extraction
TrackingField and GatherByField use the same header: or json: selector contract as other endpoints. Headers are preserved on produce, and message body parsing supports MessagePayloadType, JsonSettings, and JsonConvertSettings.
Connection Behavior
MaxReconnectAttempts lets you bound reconnect behavior for long-running produce or consume flows while keeping the endpoint contract aligned with the rest of the cross-platform runtime.
Feature Usage Samples
How to use snippets for NATS Endpoint.
Switch between C#, Java, Python, TypeScript, and JavaScript to see the native SDK shape for this sample.
Licensing note: every runnable sample requires a valid runner key via WithRunnerKey("...") or config key LoadStrike:RunnerKey.
NATS Endpoint
var endpoint = new NatsEndpointDefinition
{
Name = "nats-out",
Mode = TrafficEndpointMode.Consume,
TrackingField = TrackingFieldSelector.Parse("header:X-Correlation-Id"),
ServerUrl = "nats://localhost:4222",
Subject = "orders.completed",
QueueGroup = "loadstrike-orders",
ConnectionName = "orders-consumer"
};
import com.loadstrike.runtime.LoadStrikeCorrelation.TrackingFieldSelector;
import com.loadstrike.runtime.LoadStrikeTransports;
import com.loadstrike.runtime.NatsEndpointDefinition;
var endpoint = new NatsEndpointDefinition();
endpoint.name = "nats-out";
endpoint.mode = LoadStrikeTransports.TrafficEndpointMode.Consume;
endpoint.trackingField = TrackingFieldSelector.parse("header:X-Correlation-Id");
endpoint.serverUrl = "nats://localhost:4222";
endpoint.subject = "orders.completed";
endpoint.queueGroup = "loadstrike-orders";
endpoint.connectionName = "orders-consumer";
from loadstrike_sdk import NatsEndpointDefinition, TrackingFieldSelector
endpoint = NatsEndpointDefinition(
name="nats-out",
mode="Consume",
tracking_field=TrackingFieldSelector.parse("header:X-Correlation-Id"),
server_url="nats://localhost:4222",
subject="orders.completed",
queue_group="loadstrike-orders",
connection_name="orders-consumer",
)
import { NatsEndpointDefinition, TrackingFieldSelector } from "@loadstrike/loadstrike-sdk";
const endpoint = new NatsEndpointDefinition({
name: "nats-out",
mode: "Consume",
trackingField: TrackingFieldSelector.parse("header:X-Correlation-Id"),
serverUrl: "nats://localhost:4222",
subject: "orders.completed",
queueGroup: "loadstrike-orders",
connectionName: "orders-consumer"
});
const { NatsEndpointDefinition, TrackingFieldSelector } = require("@loadstrike/loadstrike-sdk");
const endpoint = new NatsEndpointDefinition({
name: "nats-out",
mode: "Consume",
trackingField: TrackingFieldSelector.parse("header:X-Correlation-Id"),
serverUrl: "nats://localhost:4222",
subject: "orders.completed",
queueGroup: "loadstrike-orders",
connectionName: "orders-consumer"
});
Body Example
Specifies the NATS server or cluster URL.
Specifies the NATS subject used to publish or consume messages.
Lets multiple consumers share work from the same subject when queue semantics are needed.
Labels the NATS connection for easier broker-side diagnostics.
Points to the header or body field that carries the correlation id.
{ "trackingId": "trk-1", "tenantId": "tenant-a" }