Skip to content

PURISTA API / Modules / @purista/base-http-bridge / HttpEventBridge

Class: HttpEventBridge<CustomConfig>

@purista/base-http-bridge.HttpEventBridge

The HTTP event bridge is a generic event bridge. In environments like Dapr or Knative, the communication is done via sidecar containers and via HTTP.

In these cases, it is expected, that the current instance is a HTTP server, which provides REST endpoints for commands and subscriptions. The communication from the current instance to the sidecar is also done via REST endpoints.

HTTP calls from the sidecar to the current instance might be done via CloudEvent schema, which wraps the payload into a defined structure. The HttpEventBridge can be configured to respect this, and to extract the information from CloudEvents.

To use the HttpEventBridge, you will need following peer-dependencies installed:

  • hono
  • trouter

Type parameters

NameType
CustomConfigextends HttpEventBridgeConfig

Hierarchy

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new HttpEventBridge<CustomConfig>(config, client): HttpEventBridge<CustomConfig>

Type parameters

NameType
CustomConfigextends HttpEventBridgeConfig

Parameters

NameType
config{ [K in string | number | symbol]: (Object & CustomConfig)[K] }
clientHttpEventBridgeClient

Returns

HttpEventBridge<CustomConfig>

Overrides

EventBridgeBaseClass.constructor

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:76

Properties

app

app: Hono<Env, BlankSchema, "/">

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:70


client

client: HttpEventBridgeClient

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:74


config

config: Complete<{ [K in string | number | symbol]: (Object & CustomConfig)[K] }>

Inherited from

EventBridgeBaseClass.config

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:14


defaultCommandTimeout

defaultCommandTimeout: number

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

Implementation of

EventBridge.defaultCommandTimeout

Inherited from

EventBridgeBaseClass.defaultCommandTimeout

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:17


instanceId

instanceId: string

Implementation of

EventBridge.instanceId

Inherited from

EventBridgeBaseClass.instanceId

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:16


isShuttingDown

isShuttingDown: boolean = false

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:71


isStarted

isStarted: boolean = false

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:72


logger

logger: Logger

Inherited from

EventBridgeBaseClass.logger

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:12


name

name: string

Implementation of

EventBridge.name

Inherited from

EventBridgeBaseClass.name

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:15


server

server: undefined | Server<typeof IncomingMessage, typeof ServerResponse> | Http2Server | Http2SecureServer

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:69


traceProvider

traceProvider: NodeTracerProvider

Inherited from

EventBridgeBaseClass.traceProvider

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:13

Methods

destroy

destroy(): Promise<void>

Shut down event bridge as gracefully as possible

Returns

Promise<void>

Implementation of

EventBridge.destroy

Overrides

EventBridgeBaseClass.destroy

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:355


emit

emit<K>(eventName, parameter?): void

Type parameters

NameType
Kextends EventKey<{ eventbridge-connected: never ; eventbridge-connection-error: unknown ; eventbridge-disconnected: never ; eventbridge-error: unknown ; eventbridge-reconnecting: never }>

Parameters

NameType
eventNameK
parameter?{ eventbridge-connected: never ; eventbridge-connection-error: unknown ; eventbridge-disconnected: never ; eventbridge-error: unknown ; eventbridge-reconnecting: never }[K]

Returns

void

Inherited from

EventBridgeBaseClass.emit

Defined in

core/dist/commonjs/core/types/GenericEventEmitter.d.ts:13


emitMessage

emitMessage<T>(message): Promise<Readonly<EBMessage>>

Emit a message to the eventbridge without awaiting a result

Type parameters

NameType
Textends EBMessage

Parameters

NameTypeDescription
messageOmit<EBMessage, "id" | "timestamp" | "correlationId">the message

Returns

Promise<Readonly<EBMessage>>

Implementation of

EventBridge.emitMessage

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:148


getTracer

getTracer(): Tracer

Returns open telemetry tracer of this service

Returns

Tracer

Tracer

Inherited from

EventBridgeBaseClass.getTracer

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:24


invoke

invoke<T>(input, ttl?): Promise<T>

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

Type parameters

Name
T

Parameters

NameTypeDescription
inputOmit<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: unknown ; payload: unknown } ; principalId?: string ; receiver: EBMessageAddress ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }, "id" | "timestamp" | "correlationId" | "messageType">a partial command message
ttl?numberthe time to live (timeout) of the invocation

Returns

Promise<T>

Implementation of

EventBridge.invoke

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:208


isHealthy

isHealthy(): Promise<boolean>

Indicates if the eventbridge is running and works correctly

Returns

Promise<boolean>

Implementation of

EventBridge.isHealthy

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:345


isReady

isReady(): Promise<boolean>

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

Returns

Promise<boolean>

Implementation of

EventBridge.isReady

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:341


off

off<K>(eventName, fn): void

Type parameters

NameType
Kextends EventKey<{ eventbridge-connected: never ; eventbridge-connection-error: unknown ; eventbridge-disconnected: never ; eventbridge-error: unknown ; eventbridge-reconnecting: never }>

Parameters

NameType
eventNameK
fnEventReceiver<{ eventbridge-connected: never ; eventbridge-connection-error: unknown ; eventbridge-disconnected: never ; eventbridge-error: unknown ; eventbridge-reconnecting: never }[K]>

Returns

void

Inherited from

EventBridgeBaseClass.off

Defined in

core/dist/commonjs/core/types/GenericEventEmitter.d.ts:12


on

on<K>(eventName, fn): void

Type parameters

NameType
Kextends EventKey<{ eventbridge-connected: never ; eventbridge-connection-error: unknown ; eventbridge-disconnected: never ; eventbridge-error: unknown ; eventbridge-reconnecting: never }>

Parameters

NameType
eventNameK
fnEventReceiver<{ eventbridge-connected: never ; eventbridge-connection-error: unknown ; eventbridge-disconnected: never ; eventbridge-error: unknown ; eventbridge-reconnecting: never }[K]>

Returns

void

Inherited from

EventBridgeBaseClass.on

Defined in

core/dist/commonjs/core/types/GenericEventEmitter.d.ts:11


registerCommand

registerCommand(address, cb, metadata, eventBridgeConfig): Promise<string>

Parameters

NameType
addressEBMessageAddress
cb(message: { contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: Command ; otp?: string ; payload: { parameter: unknown ; payload: unknown } ; principalId?: string ; receiver: EBMessageAddress ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }) => Promise<Readonly<Omit<{ contentEncoding: string ; contentType: string ; correlationId: string ; eventName?: string ; id: string ; messageType: CommandSuccessResponse ; otp?: string ; payload: unknown ; principalId?: string ; receiver: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }, "instanceId">> | Readonly<Omit<{ contentEncoding: "utf-8" ; contentType: "application/json" ; correlationId: string ; eventName?: string ; id: string ; isHandledError: boolean ; messageType: CommandErrorResponse ; otp?: string ; payload: { data?: unknown ; message: string ; status: StatusCode } ; principalId?: string ; receiver: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }, "instanceId">>>
metadataObject
metadata.expose{ contentEncodingRequest?: string ; contentEncodingResponse?: string ; contentTypeRequest?: string ; contentTypeResponse?: string ; deprecated?: boolean ; inputPayload?: SchemaObject ; outputPayload?: SchemaObject ; parameter?: SchemaObject } & { http: { method: "POST" | "PUT" | "PATCH" | "GET" | "DELETE" ; openApi?: { additionalStatusCodes?: StatusCode[] ; description: string ; isSecure: boolean ; operationId?: string ; query?: QueryParameter<{}>[] ; summary: string ; tags?: string[] } ; path: string } }
eventBridgeConfigDefinitionEventBridgeConfig

Returns

Promise<string>

Implementation of

EventBridge.registerCommand

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:262


registerSubscription

registerSubscription(subscription, cb): Promise<string>

Register a new subscription

Parameters

NameTypeDescription
subscriptionSubscriptionthe subscription definition
cb(message: EBMessage) => Promise<undefined | Omit<{ contentEncoding: string ; contentType: string ; correlationId?: string ; eventName: string ; id: string ; messageType: CustomMessage ; otp?: string ; payload?: unknown ; principalId?: string ; receiver?: EBMessageAddress ; sender: { instanceId: string ; serviceName: string ; serviceTarget: string ; serviceVersion: string } ; tenantId?: string ; timestamp: number ; traceId?: string }, "id" | "timestamp">>the function to be called if a matching message arrives

Returns

Promise<string>

Implementation of

EventBridge.registerSubscription

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:316


removeAllListeners

removeAllListeners(): void

Returns

void

Inherited from

EventBridgeBaseClass.removeAllListeners

Defined in

core/dist/commonjs/core/types/GenericEventEmitter.d.ts:14


start

start(): Promise<void>

Start the eventbridge and connect to the underlaying message broker

Returns

Promise<void>

Implementation of

EventBridge.start

Overrides

EventBridgeBaseClass.start

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:90


startActiveSpan

startActiveSpan<F>(name, opts, context, fn): Promise<F>

Start a child span for opentelemetry tracking

Type parameters

Name
F

Parameters

NameTypeDescription
namestringname of span
optsSpanOptionsspan options
contextundefined | Contextoptional context
fn(span: Span) => Promise<F>function to be executed within the span

Returns

Promise<F>

return value of fn

Inherited from

EventBridgeBaseClass.startActiveSpan

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:33


unregisterCommand

unregisterCommand(address): Promise<void>

Unregister a service command

Parameters

NameTypeDescription
addressEBMessageAddressThe address (service name, version and command name) of the command to be de-registered

Returns

Promise<void>

Implementation of

EventBridge.unregisterCommand

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:312


unregisterSubscription

unregisterSubscription(address): Promise<void>

Parameters

NameType
addressEBMessageAddress

Returns

Promise<void>

Implementation of

EventBridge.unregisterSubscription

Defined in

base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:337


wrapInSpan

wrapInSpan<F>(name, opts, fn, context?): Promise<F>

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

This means during logging and similar the spanId of parent span is logged.

Use wrapInSpan for marking points in flow of one bigger function, but not to trace the program flow itself

Type parameters

Name
F

Parameters

NameTypeDescription
namestringname of span
optsSpanOptionsspan options
fn(span: Span) => Promise<F>function te be executed in the span
context?Contextspan context

Returns

Promise<F>

return value of fn

Inherited from

EventBridgeBaseClass.wrapInSpan

Defined in

core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:49