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
Name | Type |
---|---|
CustomConfig | extends HttpEventBridgeConfig |
Hierarchy
EventBridgeBaseClass
<CustomConfig
>↳
HttpEventBridge
Implements
Table of contents
Constructors
Properties
Methods
- destroy
- emit
- emitMessage
- getTracer
- invoke
- isHealthy
- isReady
- off
- on
- registerCommand
- registerSubscription
- removeAllListeners
- start
- startActiveSpan
- unregisterCommand
- unregisterSubscription
- wrapInSpan
Constructors
constructor
• new HttpEventBridge<CustomConfig
>(config
, client
): HttpEventBridge
<CustomConfig
>
Type parameters
Name | Type |
---|---|
CustomConfig | extends HttpEventBridgeConfig |
Parameters
Name | Type |
---|---|
config | { [K in string | number | symbol]: (Object & CustomConfig)[K] } |
client | HttpEventBridgeClient |
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
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
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
Defined in
core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:12
name
• name: string
Implementation of
Inherited from
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
Overrides
Defined in
base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:355
emit
▸ emit<K
>(eventName
, parameter?
): void
Type parameters
Name | Type |
---|---|
K | extends EventKey <{ eventbridge-connected : never ; eventbridge-connection-error : unknown ; eventbridge-disconnected : never ; eventbridge-error : unknown ; eventbridge-reconnecting : never }> |
Parameters
Name | Type |
---|---|
eventName | K |
parameter? | { eventbridge-connected : never ; eventbridge-connection-error : unknown ; eventbridge-disconnected : never ; eventbridge-error : unknown ; eventbridge-reconnecting : never }[K ] |
Returns
void
Inherited from
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
Name | Type |
---|---|
T | extends EBMessage |
Parameters
Name | Type | Description |
---|---|---|
message | Omit <EBMessage , "id" | "timestamp" | "correlationId" > | the message |
Returns
Promise
<Readonly
<EBMessage
>>
Implementation of
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
Name | Type | Description |
---|---|---|
input | Omit <{ 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? | number | the time to live (timeout) of the invocation |
Returns
Promise
<T
>
Implementation of
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
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
Defined in
base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:341
off
▸ off<K
>(eventName
, fn
): void
Type parameters
Name | Type |
---|---|
K | extends EventKey <{ eventbridge-connected : never ; eventbridge-connection-error : unknown ; eventbridge-disconnected : never ; eventbridge-error : unknown ; eventbridge-reconnecting : never }> |
Parameters
Name | Type |
---|---|
eventName | K |
fn | EventReceiver <{ eventbridge-connected : never ; eventbridge-connection-error : unknown ; eventbridge-disconnected : never ; eventbridge-error : unknown ; eventbridge-reconnecting : never }[K ]> |
Returns
void
Inherited from
Defined in
core/dist/commonjs/core/types/GenericEventEmitter.d.ts:12
on
▸ on<K
>(eventName
, fn
): void
Type parameters
Name | Type |
---|---|
K | extends EventKey <{ eventbridge-connected : never ; eventbridge-connection-error : unknown ; eventbridge-disconnected : never ; eventbridge-error : unknown ; eventbridge-reconnecting : never }> |
Parameters
Name | Type |
---|---|
eventName | K |
fn | EventReceiver <{ eventbridge-connected : never ; eventbridge-connection-error : unknown ; eventbridge-disconnected : never ; eventbridge-error : unknown ; eventbridge-reconnecting : never }[K ]> |
Returns
void
Inherited from
Defined in
core/dist/commonjs/core/types/GenericEventEmitter.d.ts:11
registerCommand
▸ registerCommand(address
, cb
, metadata
, eventBridgeConfig
): Promise
<string
>
Parameters
Name | Type |
---|---|
address | EBMessageAddress |
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" >>> |
metadata | Object |
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 } } |
eventBridgeConfig | DefinitionEventBridgeConfig |
Returns
Promise
<string
>
Implementation of
Defined in
base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:262
registerSubscription
▸ registerSubscription(subscription
, cb
): Promise
<string
>
Register a new subscription
Parameters
Name | Type | Description |
---|---|---|
subscription | Subscription | the 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
Overrides
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
Name | Type | Description |
---|---|---|
name | string | name of span |
opts | SpanOptions | span options |
context | undefined | Context | optional 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
Name | Type | Description |
---|---|---|
address | EBMessageAddress | The address (service name, version and command name) of the command to be de-registered |
Returns
Promise
<void
>
Implementation of
Defined in
base-http-bridge/src/HttpEventBridge/HttpEventBridge.impl.ts:312
unregisterSubscription
▸ unregisterSubscription(address
): Promise
<void
>
Parameters
Name | Type |
---|---|
address | EBMessageAddress |
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
Name | Type | Description |
---|---|---|
name | string | name of span |
opts | SpanOptions | span options |
fn | (span : Span ) => Promise <F > | function te be executed in the span |
context? | Context | span context |
Returns
Promise
<F
>
return value of fn
Inherited from
EventBridgeBaseClass.wrapInSpan
Defined in
core/dist/commonjs/core/EventBridge/EventBridgeBaseClass.impl.d.ts:49