PURISTA API / @purista/base-http-bridge / HttpEventBridge
Class: HttpEventBridge<CustomConfig>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:69
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
Extends
EventBridgeBaseClass<CustomConfig>
Extended by
Type Parameters
CustomConfig
CustomConfig extends HttpEventBridgeConfig
Implements
Constructors
Constructor
new HttpEventBridge<
CustomConfig>(config,client):HttpEventBridge<CustomConfig>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:80
Parameters
config
{ [K in string | number | symbol]: ({ defaultCommandTimeout?: number; instanceId?: string; logger?: Logger; logLevel?: LogLevelName; metrics?: PuristaMetricsRuntimeOptions; metricsRecorder?: PuristaMetricsRecorderInterface; spanProcessor?: SpanProcessor } & CustomConfig)[K] }
client
Returns
HttpEventBridge<CustomConfig>
Overrides
EventBridgeBaseClass.constructor
Properties
app
app:
Hono
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:74
capabilities
capabilities:
EventBridgeCapabilities
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:28
Implementation of
Inherited from
EventBridgeBaseClass.capabilities
client
client:
HttpEventBridgeClient
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:78
config
config:
Complete<EventBridgeConfig<ConfigType>>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:26
Inherited from
defaultCommandTimeout
defaultCommandTimeout:
number
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:30
The default time until when a command invocation automatically returns a time out error
Implementation of
EventBridge.defaultCommandTimeout
Inherited from
EventBridgeBaseClass.defaultCommandTimeout
inFlightExecutions
protectedreadonlyinFlightExecutions:InFlightExecutionTracker
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:31
Inherited from
EventBridgeBaseClass.inFlightExecutions
instanceId
instanceId:
string
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:29
Implementation of
Inherited from
EventBridgeBaseClass.instanceId
isShuttingDown
isShuttingDown:
boolean=false
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:75
isStarted
isStarted:
boolean=false
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:76
logger
logger:
Logger
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:23
Inherited from
metricsRecorder
protectedmetricsRecorder:PuristaMetricsRecorderInterface
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:25
Inherited from
EventBridgeBaseClass.metricsRecorder
name
name:
string
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:27
Implementation of
Inherited from
server
server:
Server<typeofIncomingMessage, typeofServerResponse> |Http2Server<typeofIncomingMessage, typeofServerResponse, typeofHttp2ServerRequest, typeofHttp2ServerResponse> |Http2SecureServer<typeofIncomingMessage, typeofServerResponse, typeofHttp2ServerRequest, typeofHttp2ServerResponse> |undefined
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:73
traceProvider
traceProvider:
NodeTracerProvider
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:24
Inherited from
EventBridgeBaseClass.traceProvider
Methods
destroy()
destroy():
Promise<void>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:402
Shut down event bridge as gracefully as possible
Returns
Promise<void>
Implementation of
Overrides
emitMessage()
emitMessage<
T>(message):Promise<Readonly<EBMessage>>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:188
Emit a message to the eventbridge without awaiting a result
Type Parameters
T
T extends EBMessage
Parameters
message
Omit<EBMessage, "id" | "timestamp" | "correlationId">
the message
Returns
Promise<Readonly<EBMessage>>
Implementation of
getInFlightExecutionCount()
getInFlightExecutionCount():
number
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:69
Number of currently running handlers across all work kinds.
Returns
number
Implementation of
EventBridge.getInFlightExecutionCount
Inherited from
EventBridgeBaseClass.getInFlightExecutionCount
getInFlightExecutionCounts()
getInFlightExecutionCounts():
InFlightExecutionCounts
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:70
Number of currently running handlers grouped by work kind.
Returns
Implementation of
EventBridge.getInFlightExecutionCounts
Inherited from
EventBridgeBaseClass.getInFlightExecutionCounts
getPausedSubscriptionConsumers()
getPausedSubscriptionConsumers():
PausedSubscriptionConsumersByRegistrationKey
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:71
Returns paused subscription consumer states keyed by adapter registration key.
Returns
PausedSubscriptionConsumersByRegistrationKey
Implementation of
EventBridge.getPausedSubscriptionConsumers
Inherited from
EventBridgeBaseClass.getPausedSubscriptionConsumers
getTracer()
getTracer():
Tracer
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:38
Returns open telemetry tracer of this service
Returns
Tracer
Tracer
Inherited from
EventBridgeBaseClass.getTracer
invoke()
invoke<
T>(input,ttl?):Promise<T>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:243
Call a command of a service and return the result of this command
Type Parameters
T
T
Parameters
input
Omit<Command, "id" | "messageType" | "timestamp" | "correlationId">
a partial command message
ttl?
number
the time to live (timeout) of the invocation
Returns
Promise<T>
Implementation of
isHealthy()
isHealthy():
Promise<boolean>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:392
Indicates if the eventbridge is running and works correctly
Returns
Promise<boolean>
Implementation of
isReady()
isReady():
Promise<boolean>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:388
Indicates if the eventbridge has been started and is connected to underlaying message broker
Returns
Promise<boolean>
Implementation of
openStream()
openStream<
Chunk,Final>(_input,_ttl?):Promise<StreamHandle<Chunk,Final>>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:73
Open a stream invocation. The returned handle can be consumed via async iteration and can be cancelled by caller.
Type Parameters
Chunk
Chunk = unknown
Final
Final = unknown
Parameters
_input
Omit<StreamOpenRequest, "id" | "messageType" | "timestamp" | "correlationId">
_ttl?
number
Returns
Promise<StreamHandle<Chunk, Final>>
Implementation of
Inherited from
EventBridgeBaseClass.openStream
registerCommand()
registerCommand(
address,cb,metadata,eventBridgeConfig):Promise<string>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:299
Parameters
address
the address of the service command (service name, version and command name)
cb
(message) => 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">>>
the function to be called if a matching command arrives
metadata
expose
object & object
eventBridgeConfig
Returns
Promise<string>
Implementation of
registerStream()
registerStream(
_address,_cb,_metadata,_eventBridgeConfig):Promise<string>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:74
Register a service stream.
Parameters
_address
_cb
(message) => Promise<void>
_metadata
_eventBridgeConfig
Returns
Promise<string>
Implementation of
Inherited from
EventBridgeBaseClass.registerStream
registerSubscription()
registerSubscription(
subscription,cb):Promise<string>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:362
Register a new subscription
Parameters
subscription
the subscription definition
cb
(message) => Promise<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"> | undefined>
the function to be called if a matching message arrives
Returns
Promise<string>
Implementation of
EventBridge.registerSubscription
resumeSubscriptionConsumer()
resumeSubscriptionConsumer(
_registrationKey):Promise<void>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:72
Resumes a paused subscription consumer by registration key.
Parameters
_registrationKey
string
Returns
Promise<void>
Implementation of
EventBridge.resumeSubscriptionConsumer
Inherited from
EventBridgeBaseClass.resumeSubscriptionConsumer
runInFlight()
runInFlight<
T>(fn,kind?):Promise<T>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:67
Type Parameters
T
T
Parameters
fn
() => Promise<T>
kind?
"command" | "subscription" | "stream" | "generic"
Returns
Promise<T>
Inherited from
EventBridgeBaseClass.runInFlight
start()
start():
Promise<void>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:128
Start the eventbridge and connect to the underlaying message broker
Returns
Promise<void>
Implementation of
Overrides
startActiveSpan()
startActiveSpan<
F>(name,opts,context,fn):Promise<F>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:47
Start a child span for opentelemetry tracking
Type Parameters
F
F
Parameters
name
string
name of span
opts
SpanOptions
span options
context
Context | undefined
optional context
fn
(span) => Promise<F>
function to be executed within the span
Returns
Promise<F>
return value of fn
Inherited from
EventBridgeBaseClass.startActiveSpan
unregisterCommand()
unregisterCommand(
address):Promise<void>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:358
Unregister a service command
Parameters
address
The address (service name, version and command name) of the command to be de-registered
Returns
Promise<void>
Implementation of
unregisterStream()
unregisterStream(
_address):Promise<void>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:75
Unregister a service stream
Parameters
_address
Returns
Promise<void>
Implementation of
Inherited from
EventBridgeBaseClass.unregisterStream
unregisterSubscription()
unregisterSubscription(
address):Promise<void>
Defined in: base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:384
Parameters
address
Returns
Promise<void>
Implementation of
EventBridge.unregisterSubscription
waitForInFlightDrain()
waitForInFlightDrain(
timeoutMs?):Promise<boolean>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:68
Parameters
timeoutMs?
number
Returns
Promise<boolean>
Inherited from
EventBridgeBaseClass.waitForInFlightDrain
wrapInSpan()
wrapInSpan<
F>(name,opts,fn,context?):Promise<F>
Defined in: core/dist/core/EventBridge/EventBridgeBaseClass.impl.d.ts:64
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
F
F
Parameters
name
string
name of span
opts
SpanOptions
span options
fn
(span) => Promise<F>
function te be executed in the span
context?
Context
span context
Returns
Promise<F>
return value of fn
