Classes · @purista/core

DefaultEventBridge

Process-local in-memory event bridge for development and tests.

Signature

DefaultEventBridge.tstypescript
class DefaultEventBridge

Examples

example-1.tstypescript
import { DefaultEventBridge } from '@purista/core'

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

// add your services

Constructors

1 entry

constructor

Constructor

Source
constructor.tstypescript
new constructor(config?: { defaultCommandTimeout: number; instanceId: string; logger: Logger; logLevel: LogLevelName; logWarnOnMessagesWithoutReceiver: boolean; metrics: PuristaMetricsRuntimeOptions; ... })

Properties

18 entries

capabilities

Property

Source
capabilities.tstypescript
capabilities: EventBridgeCapabilities

Runtime capability matrix used for strict startup validation.

config

Property

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

defaultCommandTimeout

Property

Source
defaultCommandTimeout.tstypescript
defaultCommandTimeout: number

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

hasStarted

Property

Source
hasStarted.tstypescript
hasStarted: boolean

healthy

Property

Source
healthy.tstypescript
healthy: boolean

inFlightExecutions

Property

Source
inFlightExecutions.tstypescript
inFlightExecutions: InFlightExecutionTracker

instanceId

Property

Source
instanceId.tstypescript
instanceId: string

Stable runtime instance id used to distinguish bridge processes.

logger

Property

Source
logger.tstypescript
logger: Logger

metricsRecorder

Property

Source
metricsRecorder.tstypescript
metricsRecorder: PuristaMetricsRecorder

name

Property

Source
name.tstypescript
name: string

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

pendingInvocations

Property

Source
pendingInvocations.tstypescript
pendingInvocations: PendingInvocationRegistry<unknown>

pendingStreams

Property

Source
pendingStreams.tstypescript
pendingStreams: PendingStreamRegistry<any, any>

readStream

Property

Source
readStream.tstypescript
readStream: Readable

serviceFunctions

Property

Source
serviceFunctions.tstypescript
serviceFunctions: Map<string, (message: { contentEncoding: string; contentType: string; correlationId: string; eventName: string; id: string; messageType: Command; ... }) => Promise<{ contentEncoding: unknown; contentType: unknown; correlationId: unknown; eventName: unknown; id: unknown; isHandledError: unknown; ... } | { contentEncoding: unknown; contentType: unknown; correlationId: unknown; eventName: unknown; id: unknown; messageType: unknown; ... }>>

streamFunctions

Property

Source
streamFunctions.tstypescript
streamFunctions: Map<string, (message: StreamMessage) => Promise<void>>

subscriptions

Property

Source
subscriptions.tstypescript
subscriptions: Map<string, SubscriptionStorageEntry>

traceProvider

Property

Source
traceProvider.tstypescript
traceProvider: NodeTracerProvider

writeStream

Property

Source
writeStream.tstypescript
writeStream: Writable

Methods

22 entries

destroy

Method

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

Shut down event bridge as gracefully as possible

emitMessage

Method

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

Emit a new message to event bridge to be delivered to receiver

getInFlightExecutionCount

Method

Source
getInFlightExecutionCount.tstypescript
getInFlightExecutionCount(): number

Number of currently running handlers across all work kinds.

getInFlightExecutionCounts

Method

Source
getInFlightExecutionCounts.tstypescript
getInFlightExecutionCounts(): InFlightExecutionCounts

Number of currently running handlers grouped by work kind.

getPausedSubscriptionConsumers

Method

Source
getPausedSubscriptionConsumers.tstypescript
getPausedSubscriptionConsumers(): PausedSubscriptionConsumersByRegistrationKey

Returns paused subscription consumer states keyed by adapter registration key.

getTracer

Method

Source
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>

Call a command of a service and return the result of this command

isHealthy

Method

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

Indicates if the eventbridge is running and works correctly

isReady

Method

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

Indicates if the eventbridge has been started and is connected to underlaying message broker

openStream

Method

Source
openStream.tstypescript
openStream<Chunk, Final>(input: Omit<StreamOpenRequest, "id" | "messageType" | "timestamp" | "correlationId">, commandTimeout: 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): Promise<string>

Register a service command and ensure that there is a queue for all incoming command requests.

registerStream

Method

Source
registerStream.tstypescript
registerStream(address: EBMessageAddress, cb: (message: StreamMessage) => Promise<void>, metadata: StreamDefinitionMetadataBase): 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>

Register a new subscription.

resumeSubscriptionConsumer

Method

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

Resumes a paused subscription consumer by registration key.

runInFlight

Method

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

start

Method

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

Start the eventbridge and connect to the underlaying message broker

startActiveSpan

Method

Source
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>

Unregister a service command

unregisterStream

Method

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

Unregister a service stream

unregisterSubscription

Method

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

Unregister a subscription.

waitForInFlightDrain

Method

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

wrapInSpan

Method

Source
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!