NATS Triggers
Orvanta enables integration with NATS servers to activate runnables (scripts, flows) upon message receipt. The listening mechanism operates from servers without consuming worker resources. This functionality is exclusive to self-hosted Enterprise deployments.
How to use
Section titled “How to use”Core NATS
Section titled “Core NATS”Establish a fresh trigger via the NATS triggers interface. Configure a NATS resource by supplying server hostnames in the format hostname[:port] (excluding the nats:// prefix) along with authentication details. Designate the subjects for the trigger to monitor, with wildcard support available. Core NATS restricts configuration to a single subject.
Upon completing the NATS resource and trigger configuration, designate the runnable for activation. The received message payload, encoded in base64, transfers to the runnable as a string parameter labeled payload.
Sample script implementation:
export async function main(payload: string) { // do something with the message}With a preprocessor, the script structure becomes:
export async function preprocessor( event: { kind: "nats", payload: string, // base64 encoded payload servers: string[]; subject: string; // the specific subject the message was received from length: number; headers?: Record<string, string[]>; status?: number; description?: string; }) { if (event.kind !== "nats") { throw new Error(`Expected a nats event`); } // assuming the message is a JSON object const msg = JSON.parse(atob(event.payload));
// define args for the main function // let's assume we want to use the message content and the subject return { message_content: msg.content, subject: event.subject };}
export async function main(message_content: string, subject: string) { // do something with the message content and subject}JetStream
Section titled “JetStream”JetStream support facilitates persistence and simultaneous monitoring of multiple subjects. Persistence ensures message delivery upon reconnection, even after temporary interruptions.
When specified, a stream initializes automatically if absent. For existing streams, configuration adapts to incorporate designated subjects while preserving existing settings. Stream subjects remain unless manually removed.
A durable push-consumer instantiates with the designated name and subjects. Pre-existing consumers receive replacement. The consumer designation serves as the DeliverSubject — ensure uniqueness.
Error handling
Section titled “Error handling”NATS triggers accommodate localized error handlers that supersede workspace-level handlers for designated triggers.