Skip to content

NATS publisher ​

Publishes every incoming EventData record to a NATS subject (core NATS, at-most-once) using the CloudEvents NATS binding in binary content mode: attributes travel as ce-* headers, the payload is the raw message body.

Pins ​

PinKindTypesDescription
InputinputViaducta.Plugins.Event.Types.EventDataEvent to publish.
Continuecontinuesame as inputCalled with the unchanged input after the message was handed to the NATS connection.

Configuration ​

The configuration is shared with the NATS subscriber; fields marked subscriber only have no effect here.

FieldTypeDefaultDescription
Urlstring (max 1024)Required. Server url, e.g. nats://host:4222. Several cluster urls comma separated.
Subjectstring (max 255)Required. Subject to publish to (no wildcards).
ConnectTimeoutMsinteger (min 1)5000Connect timeout in milliseconds.
AuthTypedropdown: 0 None, 1 UserPassword, 2 Token, 3 NKey, 4 Creds0How the client authenticates.
Usernamestring (max 256)Required when AuthType is 1.
Passwordpassword (max 256)Used when AuthType is 1.
TokenpasswordRequired when AuthType is 2.
NKeystringNKey public key. Required (with Seed) when AuthType is 3.
SeedpasswordNKey seed (private key). Required when AuthType is 3.
CredstextWhole content of the .creds file (JWT and NKey seed). Required when AuthType is 4.
UseTlsbooleanfalsetrue: TLS is required.
InsecureSkipVerifybooleanfalseVisible with UseTls. Skips server certificate verification. Development only.
CaCertificatecertificate nameVisible with UseTls. CA used to verify the server certificate (private CA). Empty: OS trust store.
ClientCertificatecertificate nameVisible with UseTls. Client certificate with private key for mutual TLS.
AllowSubjectOverridebooleanfalsetrue: a non-empty EventData.Channel is used as the subject instead of Subject.
DefaultSourcestring (max 512)CloudEvents source for events without one. Empty: viaducta://{flow}/{component}.
DefaultTypestring (max 255)com.viaducta.eventCloudEvents type for events without one.
QueueGroupstring (max 255)Not used by the publisher (subscriber setting).
PendingCapacityinteger (min 1)1024Not used by the publisher (subscriber setting).
PendingFullModedropdown: 0 Wait, 1 DropNewest, 2 DropOldest, 3 DropWrite2Not used by the publisher (subscriber setting).

Behaviour ​

  • The connection is opened at flow start. Invalid configuration, a missing certificate or a failed first connect stops the flow with an unrecoverable error (no retry on the initial connect). After that, connection losses are reconnected automatically and logged as warnings. The plugin keeps the flow running (KeepAlive).
  • Message built from the input EventData:
    • body = Data (null gives an empty body), reply subject = ReplyTo if set,
    • Headers → message headers, except keys that clash with the core ce-* attributes (those are dropped),
    • ce-id = Id (new random GUID if empty), ce-source = Source or the default source, ce-specversion = SpecVersion or 1.0, ce-type = Type or DefaultType, ce-time = Time in UTC (now if empty),
    • ce-datacontenttype and ce-subject only when DataContentType / Subject are set.
  • The input record is not modified; defaults are applied only to the headers.
  • A failed publish (payload too large, invalid subject or header, timeout while disconnected) raises a recoverable error for that record; the next record is tried again.

Notes ​

  • No delivery confirmation: core NATS is fire-and-forget. Continue means the connection accepted the message, not that a subscriber received it. Messages with no subscriber listening are lost. JetStream is not supported.
  • EventData.Subject is the CloudEvents subject, not the NATS subject. To route per record set Channel and enable AllowSubjectOverride.
  • Set ReplyTo to have receivers answer on a reply subject; the publisher itself does not wait for replies.
  • With InsecureSkipVerify set, CaCertificate is ignored.
  • Keep secrets in expression settings, e.g. "Token": "=Secrets.NatsToken".

Example ​

json
{ "Url": "nats://nats.local:4222", "Subject": "orders.created", "DefaultType": "com.example.order.created", "AuthType": 2, "Token": "=Secrets.NatsToken" }

Http listener → Script (build EventData) → NATS publisher → Http response

Viaducta documentation