Packages · @purista/natsbridge

@purista/natsbridge

Package for using a [NATS](https://nats.io/) broker as event bridge. The event bridge supports brokers with and without JetStream enabled.

Signature

@purista/natsbridge.ts typescript
@purista/natsbridge

Examples

example-1.ts typescript
import { NatsBridge } from '@purista/natsbridge'

// create and init our eventbridge
  const eventBridge = new NatsBridge()
  await eventBridge.start()

Classes

1 entry

NatsBridge

Classes

Source
NatsBridge.ts typescript
class NatsBridge

EventBridge implementation for NATS core messaging with optional JetStream.

Type Aliases

9 entries

GetCommandTopicFn

Types

Source
GetCommandTopicFn.ts typescript
type GetCommandTopicFn = (this: INatsBridge, address: EBMessageAddress) => string

Function signature for building a NATS command subscription subject.

GetSubscriptionTopicFn

Types

Source
GetSubscriptionTopicFn.ts typescript
type GetSubscriptionTopicFn = (this: INatsBridge, subscription: Subscription) => string

Function signature for building a NATS subscription subject filter.

GetTopicNameFn

Types

Source
GetTopicNameFn.ts typescript
type GetTopicNameFn = (this: INatsBridge, message: EBMessage) => string

Function signature for building a NATS publish subject from a PURISTA message.

INatsBridge

Types

Source
INatsBridge.ts typescript
type INatsBridge = { connection: NatsConnection | undefined; sc: Codec<unknown> } & EventBridgeBaseClass<NatsBridgeConfig>

Internal receiver shape used by exported NATS helper functions.

IncomingMessageFunction

Types

Source
IncomingMessageFunction.ts typescript
type IncomingMessageFunction = (this: INatsBridge, error: NatsError | null, msg: Msg | JsMsg) => Promise<void>

NATS message handler bound to an INatsBridge instance.

NatsBridgeConfig

Types

Source
NatsBridgeConfig.ts typescript
type NatsBridgeConfig = Prettify<{ commandResponsePublishTwice: "always" | "eventOnly" | "eventAndError" | "never"; defaultConsumerFailureHandling: NatsConsumerFailureHandlingDefaults; defaultMessageExpiryInterval: number; durableSubscriptionMode: "strict" | "best-effort"; emptyTopicPartString: string; jetStreamAckWaitMs: number; ... } & ConnectionOptions>

Configuration for NatsBridge.

NatsConsumerFailureHandlingDefaults

Types

Source
NatsConsumerFailureHandlingDefaults.ts typescript
type NatsConsumerFailureHandlingDefaults = void

Default JetStream-backed subscription failure handling.

PausedSubscriptionState

Types

Source
PausedSubscriptionState.ts typescript
type PausedSubscriptionState = void

Runtime pause metadata for a subscription consumer managed by the NATS bridge.

RegisteredSubscription

Types

Source
RegisteredSubscription.ts typescript
type RegisteredSubscription = void

NATS or JetStream subscription tracked by the bridge for cleanup.

Variables

4 entries

getCommandSubscriptionTopic

Variables

Source
getCommandSubscriptionTopic.ts typescript
const getCommandSubscriptionTopic: GetCommandTopicFn

Builds the NATS subject used by command handlers for one service address.

getSubscriptionTopic

Variables

Source
getSubscriptionTopic.ts typescript
const getSubscriptionTopic: GetSubscriptionTopicFn

Builds the NATS subject filter for a PURISTA subscription definition.

getTopicName

Variables

Source
getTopicName.ts typescript
const getTopicName: GetTopicNameFn

Calculates the NATS topic name for a message which should be sent.

puristaVersion

Variables

Source
puristaVersion.ts typescript
const puristaVersion: "3.0.1"

The PURISTA package version embedded in the published runtime build.

Functions

2 entries

getDefaultNatsBridgeConfig

Functions

Source
getDefaultNatsBridgeConfig.ts typescript
getDefaultNatsBridgeConfig(): { commandResponsePublishTwice: "always" | "eventOnly" | "eventAndError" | "never"; defaultConsumerFailureHandling: NatsConsumerFailureHandlingDefaults; defaultMessageExpiryInterval: number; durableSubscriptionMode: "strict" | "best-effort"; emptyTopicPartString: string; jetStreamAckWaitMs: number; ... }

getQueueGroupName

Functions

Source
getQueueGroupName.ts typescript
getQueueGroupName(prefix: string, address: EBMessageAddress): string