> ## Documentation Index
> Fetch the complete documentation index at: https://abxbus.archivebox.io/llms.txt
> Use this file to discover all available pages before exploring further.

# NATSEventBridge

> Forward events over NATS subjects.

`NATSEventBridge` publishes events to a NATS subject and subscribes to the same subject for inbound forwarding.

## Go support

<Tabs>
  <Tab title="Go">
    `NATSEventBridge` is not implemented in `abxbus-go` yet. Use [JSONLEventBridge](./bridge-jsonl) for the currently supported Go bridge.
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // Not implemented in the Rust crate yet.
    // Use typed event JSON serialization with an external transport for now.
    ```
  </Tab>
</Tabs>

## Optional dependencies

<Tabs>
  <Tab title="Python">
    Install the NATS extra (recommended):

    ```bash theme={null}
    pip install "abxbus[nats]"
    ```

    Equivalent direct dependency install:

    ```bash theme={null}
    pip install nats-py
    ```
  </Tab>

  <Tab title="TypeScript">
    Install the NATS client package:

    ```bash theme={null}
    npm install abxbus nats
    ```

    This bridge is Node.js-only.
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // NATSEventBridge is not implemented in abxbus-go yet.
    // Use JSONLEventBridge for the currently supported Go bridge.
    ```
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // Not implemented in the Rust crate yet.
    // Use typed events plus EventBus JSON serialization with an external transport for now.
    ```
  </Tab>
</Tabs>

## Constructor params

* `server`: NATS server URL (for example `nats://localhost:4222`)
* `subject`: subject name used for publish/subscribe
* `name`: optional bridge label

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from abxbus.bridges import NATSEventBridge

    bridge = NATSEventBridge(
        'nats://localhost:4222',
        'abxbus_events',
        name='NatsBridge',
    )
    ```
  </Tab>

  <Tab title="TypeScript">
    ```ts theme={null}
    import { NATSEventBridge } from 'abxbus/bridges'

    const bridge = new NATSEventBridge(
      'nats://localhost:4222',
      'abxbus_events',
      'NatsBridge'
    )
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // NATSEventBridge is not implemented in abxbus-go yet.
    // Use JSONLEventBridge for Go process-to-process bridge tests and deployments.
    ```
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // Not implemented in the Rust crate yet.
    // Use typed events plus EventBus JSON serialization with an external transport for now.
    ```
  </Tab>
</Tabs>

## Setup with a bus

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from abxbus import EventBus
    from abxbus.bridges import NATSEventBridge

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

    bus.on('*', bridge.emit)
    bridge.on('*', bus.emit)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```ts theme={null}
    import { EventBus } from 'abxbus'
    import { NATSEventBridge } from 'abxbus/bridges'

    const bus = new EventBus('AppBus')
    const bridge = new NATSEventBridge('nats://localhost:4222', 'abxbus_events')

    bus.on('*', bridge.emit)
    bridge.on('*', bus.emit)
    ```
  </Tab>

  <Tab title="Go">
    ```go theme={null}
    // NATSEventBridge is not implemented in abxbus-go yet.
    // Use JSONLEventBridge for Go process-to-process bridge tests and deployments.
    ```
  </Tab>

  <Tab title="Rust">
    ```rust theme={null}
    // Not implemented in the Rust crate yet.
    // Use typed events plus EventBus JSON serialization with an external transport for now.
    ```
  </Tab>
</Tabs>

## 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.
