Skip to main content
NATSEventBridge publishes events to a NATS subject and subscribes to the same subject for inbound forwarding.

Optional dependencies

Install the NATS extra (recommended):
pip install "bubus[nats]"
Equivalent direct dependency install:
pip install nats-py

Constructor params

  • server: NATS server URL (for example nats://localhost:4222)
  • subject: subject name used for publish/subscribe
  • name: optional bridge label
from bubus import NATSEventBridge

bridge = NATSEventBridge(
    'nats://localhost:4222',
    'bubus_events',
    name='NatsBridge',
)

Setup with a bus

from bubus import EventBus, NATSEventBridge

bus = EventBus('AppBus')
bridge = NATSEventBridge('nats://localhost:4222', 'bubus_events')

bus.on('*', bridge.emit)
bridge.on('*', bus.emit)

Behavior

  • emit(...) publishes serialized event JSON bytes to the configured subject.
  • on(...) registers inbound handlers and auto-starts subscription.
  • Inbound messages are decoded, reset, and re-emitted on the internal bus.
  • close() drains/closes NATS connections and stops the internal bus.
  • Runtime requirements: Python needs nats-py, TypeScript needs nats and Node.js.