Skip to content

NATS Operation Binding v0.1.0

The NATS operation binding defines how AsyncAPI operations (publish and subscribe) are implemented over the NATS protocol. This binding configures how messages are sent and received using NATS subjects and queue groups, enabling scalable and load-balanced messaging.

NATS operation bindings configure the behavior of publish and subscribe operations within the NATS messaging system. A key feature of the NATS operation binding is the ability to define a queue group, which allows for load balancing of messages among multiple subscribers.

Property Type Required Description
bindingVersion string No Binding version (defaults to 0.1.0)
queue string No The name of the queue group. Max length is 255 characters.

Specifies the version of the NATS operation binding being used.

Default: 0.1.0

Defines the name of the NATS queue group to which the subscriber will subscribe. When multiple subscribers join the same queue group, messages are distributed randomly among them, ensuring that only one subscriber in the group receives any given message.

Constraints:

  • Must not exceed 255 characters.

Publish operations in NATS represent sending messages to subjects:

  • PUB Command: Used to send messages to specific NATS subjects.
  • Subject Routing: Messages are broadcast to all subscribers of the subject.
  • No Persistence (Core NATS): Messages are not stored and are lost if no subscribers are active.

Subscribe operations in NATS represent receiving messages from subjects:

  • SUB Command: Used to listen to messages on specific subjects.
  • Queue Groups: Subscribers can join a queue group to load balance message processing.
  • Real-time Delivery: Messages are delivered immediately to active subscribers.

NATS queue groups provide load balancing for subscribers:

  • Shared Subscription: Multiple subscribers subscribe to the same subject and queue group.
  • Message Distribution: Only one subscriber in the queue group receives each message.
  • Scalability: Allows for horizontal scaling of message processing.
  • No Message Ordering: No guarantee of message delivery order within the group.
operations:
sendMessage:
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'worker-queue'
operations:
publishEvent:
action: publish
channel:
$ref: '#/channels/userEvents'
bindings:
nats:
bindingVersion: '0.1.0'
operations:
subscribeToEvents:
action: subscribe
channel:
$ref: '#/channels/userEvents'
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'user-event-processors'
channels:
mathService:
address: 'math.add'
messages:
addRequest:
$ref: '#/components/messages/AddRequest'
addResponse:
$ref: '#/components/messages/AddResponse'
bindings:
nats:
bindingVersion: '0.1.0'
operations:
processOrder:
action: subscribe
channel:
$ref: '#/channels/newOrders'
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'order-processing-workers'
operations:
processTelemetry:
action: subscribe
channel:
$ref: '#/channels/deviceTelemetry'
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'telemetry-ingestion-service'
operations:
processImage:
action: subscribe
channel:
$ref: '#/channels/imageUploads'
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'image-processing-nodes'
operations:
monitorSystem:
action: subscribe
channel:
$ref: '#/channels/systemAlerts'
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'alert-monitoring-group'
  • Use descriptive and consistent queue group names.
  • Avoid using the same queue name for different subjects unless intended.
  • Keep queue names concise and meaningful.
  • Implement proper connection lifecycle handling.
  • Use connection pooling for high-throughput applications.
  • Handle reconnection scenarios gracefully.
  • Monitor connection health and performance.
  • Use appropriate message sizes.
  • Scale subscribers within a queue group to match message load.
  • Monitor operation performance and throughput.
  • Use JetStream for persistent and ordered messaging when needed.
  • Use secure NATS connections (NATS over TLS).
  • Implement proper authentication and authorization.
  • Validate all message content.
  • Protect against common messaging vulnerabilities.
  • Implement proper error handling for failed operations.
  • Handle connection failures gracefully.
  • Log operation failures for debugging.
  • Implement retry mechanisms when appropriate.
channels:
updates:
publish:
operationId: publishUpdate
bindings:
nats:
bindingVersion: '0.1.0'
subscribe:
operationId: receiveUpdate
bindings:
nats:
bindingVersion: '0.1.0'
channels:
tasks:
publish:
operationId: submitTask
bindings:
nats:
bindingVersion: '0.1.0'
subscribe:
operationId: processTask
bindings:
nats:
bindingVersion: '0.1.0'
queue: 'task-workers'
channels:
api.requests:
publish: # The request
operationId: sendRequest
bindings:
nats:
bindingVersion: '0.1.0'
subscribe: # The reply
operationId: receiveReply
bindings:
nats:
bindingVersion: '0.1.0'
  • Initial release with NATS operation binding support.
  • Support for queue group configuration for load balancing.
  • Minimal configuration focused on core NATS capabilities.
  • Schema validation for binding version.