Skip to main content

NATS event bridge


The NATS message brokeropen in new window is a fast and scalable message broker.

PURISTA provides the @purista/natsbridge


  • allows scaling
  • fault tollerant
  • can be used with NATS State store (@purista/nats-state-store)
  • can be used with NATS Config store (@purista/nats-config-store)


  • needs managing of an NATS broker
  • no persistance of messages available
  • hard to handle dead letters


The NATS event bridge uses the unified configuration schema as all event bridges.


import { NatsBridge } from '@purista/natsbridge'

const eventBridge = new NatsBridge()
await eventBridge.start()

Topic names

The NATS protocol relays on topics for message publishing/subscribe.

PURISTA is using the following schema for topics:

const topicPrefix = config.topicPrefix
const empty = config.emptyTopicPartString

const path join(
  convertToSnakeCase(message.principalId || empty),
  convertToSnakeCase(message.tenantId || empty),
  convertToSnakeCase(message.sender.instanceId || empty),
  convertToSnakeCase(message.eventName || empty),
  convertToSnakeCase((message as Command).receiver?.instanceId || empty),
  convertToSnakeCase((message as Command).receiver?.serviceName || empty),
  convertToSnakeCase((message as Command).receiver?.serviceVersion || empty),
  convertToSnakeCase((message as Command).receiver?.serviceTarget || empty),

This allows to have subscriptions for very specific messages.
The NATS event bridge does not use the available request-response pattern of NATS to be able to use the unified topic schema.
Otherwise, there would be the need to duplicate command response to be available for subscriptions.


Ensure settings across instances

Remember to ensure, prefixes, and so on are the same on every event bridge instance.
Otherwise, you might get some unexpected behaviors.


PURISTA is using the NATS header feature to add the OpenTelemetry information to each message, as recommended: in new window.

You can follow updated on Twitter @purista_jsopen in new window or join the Discord serveropen in new window to get in touch with PURISTA maintainers and other developers.

Last update:
Contributors: Sebastian Wessel