Classes · @purista/mqttbridge

MqttBridge

EventBridge implementation for MQTT 5 brokers.

Signature

MqttBridge.tstypescript
class MqttBridge

Examples

example-1.tstypescript
import { MqttBridge } from '@purista/mqttbridge'

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

Constructors

1 entry

constructor

Constructor

Source
constructor.tstypescript
new constructor(config?: { allowRetries: boolean; defaultCommandTimeout: number; defaultMessageExpiryInterval: number; defaultSessionExpiryInterval: number; emptyTopicPartString: string; instanceId: string; ... })

Creates an MQTT bridge with defaults merged into MQTT client options.

Properties

11 entries

capabilities

Property

capabilities.tstypescript
capabilities: EventBridgeCapabilities

Runtime capability matrix used for strict startup validation.

client

Property

Source
client.tstypescript
client: MqttClient | undefined

MQTT client instance, available after start.

config

Property

config.tstypescript
config: Complete<EventBridgeConfig<ConfigType>>

defaultCommandTimeout

Property

defaultCommandTimeout.tstypescript
defaultCommandTimeout: number

The default time until when a command invocation automatically returns a time out error

inFlightExecutions

Property

inFlightExecutions.tstypescript
inFlightExecutions: InFlightExecutionTracker

instanceId

Property

instanceId.tstypescript
instanceId: string

Stable runtime instance id used to distinguish bridge processes.

logger

Property

logger.tstypescript
logger: Logger

metricsRecorder

Property

metricsRecorder.tstypescript
metricsRecorder: PuristaMetricsRecorder

name

Property

name.tstypescript
name: string

Human-readable bridge name used in logs, traces, and metrics.

pendingInvocations

Property

Source
pendingInvocations.tstypescript
pendingInvocations: PendingInvocationRegistry<unknown>

Pending command invocations waiting for MQTT correlation responses.

traceProvider

Property

traceProvider.tstypescript
traceProvider: NodeTracerProvider

Methods

22 entries

destroy

Method

Source
destroy.tstypescript
destroy(): Promise<void>

Rejects pending invocations, waits for in-flight handlers, and closes the MQTT client.

emitMessage

Method

Source
emitMessage.tstypescript
emitMessage<T>(message: Omit<EBMessage, "id" | "timestamp" | "correlationId">, contentType: string, contentEncoding: string): Promise<Readonly<EBMessage>>

Publishes a PURISTA event/message as a JSON MQTT payload.

getInFlightExecutionCount

Method

getInFlightExecutionCount.tstypescript
getInFlightExecutionCount(): number

Number of currently running handlers across all work kinds.

getInFlightExecutionCounts

Method

getInFlightExecutionCounts.tstypescript
getInFlightExecutionCounts(): InFlightExecutionCounts

Number of currently running handlers grouped by work kind.

getPausedSubscriptionConsumers

Method

getPausedSubscriptionConsumers.tstypescript
getPausedSubscriptionConsumers(): PausedSubscriptionConsumersByRegistrationKey

Returns paused subscription consumer states keyed by adapter registration key.

getTracer

Method

getTracer.tstypescript
getTracer(): Tracer

Returns open telemetry tracer of this service

invoke

Method

Source
invoke.tstypescript
invoke<T>(input: Omit<Command, "id" | "messageType" | "timestamp" | "correlationId">, commandTimeout: number): Promise<T>

Invokes a command over MQTT and waits for a correlated response message.

isHealthy

Method

Source
isHealthy.tstypescript
isHealthy(): Promise<boolean>

Indicates whether the MQTT client is connected.

isReady

Method

Source
isReady.tstypescript
isReady(): Promise<boolean>

Indicates whether the MQTT client is connected.

openStream

Method

openStream.tstypescript
openStream<Chunk, Final>(_input: Omit<StreamOpenRequest, "id" | "messageType" | "timestamp" | "correlationId">, _ttl?: number): Promise<StreamHandle<Chunk, Final>>

Open a stream invocation.

registerCommand

Method

Source
registerCommand.tstypescript
registerCommand(address: EBMessageAddress, cb: (message: { contentEncoding: string; contentType: string; correlationId: string; eventName: string; id: string; messageType: Command; ... }) => Promise<{ contentEncoding: "utf-8"; contentType: "application/json"; correlationId: string; eventName: string; id: string; isHandledError: boolean; ... } | { contentEncoding: string; contentType: string; correlationId: string; eventName: string; id: string; messageType: CommandSuccessResponse; ... }>, metadata: CommandDefinitionMetadataBase, eventBridgeConfig: DefinitionEventBridgeConfig): Promise<string>

Registers a command handler on the shared MQTT command topic.

registerStream

Method

registerStream.tstypescript
registerStream(_address: EBMessageAddress, _cb: (message: StreamMessage) => Promise<void>, _metadata: StreamDefinitionMetadataBase, _eventBridgeConfig: DefinitionEventBridgeConfig): Promise<string>

Register a service stream handler for a service target.

registerSubscription

Method

Source
registerSubscription.tstypescript
registerSubscription(subscription: Subscription, cb: (message: EBMessage) => Promise<Omit<{ contentEncoding: unknown; contentType: unknown; correlationId: unknown; eventName: unknown; id: unknown; messageType: unknown; ... }, unknown | unknown> | undefined>): Promise<string>

Registers a subscription handler on a topic derived from the subscription filter.

resumeSubscriptionConsumer

Method

resumeSubscriptionConsumer.tstypescript
resumeSubscriptionConsumer(_registrationKey: string): Promise<void>

Resumes a paused subscription consumer by registration key.

runInFlight

Method

runInFlight.tstypescript
runInFlight<T>(fn: () => Promise<T>, kind?: "command" | "subscription" | "stream" | "generic"): Promise<T>

start

Method

Source
start.tstypescript
start(): Promise<void>

Connects to the MQTT broker and subscribes to this instance's command response topic.

startActiveSpan

Method

startActiveSpan.tstypescript
startActiveSpan<F>(name: string, opts: SpanOptions, context: Context | undefined, fn: (span: Span) => Promise<F>): Promise<F>

Start a child span for opentelemetry tracking

unregisterCommand

Method

Source
unregisterCommand.tstypescript
unregisterCommand(address: EBMessageAddress): Promise<void>

Unsubscribes a command handler topic and removes it from the local router.

unregisterStream

Method

unregisterStream.tstypescript
unregisterStream(_address: EBMessageAddress): Promise<void>

Unregister a service stream

unregisterSubscription

Method

Source
unregisterSubscription.tstypescript
unregisterSubscription(address: EBMessageAddress): Promise<void>

Unsubscribes and removes a registered subscription handler.

waitForInFlightDrain

Method

waitForInFlightDrain.tstypescript
waitForInFlightDrain(timeoutMs?: number): Promise<boolean>

wrapInSpan

Method

wrapInSpan.tstypescript
wrapInSpan<F>(name: string, opts: SpanOptions, fn: (span: Span) => Promise<F>, context?: Context): Promise<F>

Start span for opentelemetry tracking on same level. The created span will not become the "active" span within opentelemetry!