Skip to content

API reference / @node-ts/bus-core / Handler

Interface: Handler<TMessage, TMessageAttributes> ​

Defined in: packages/bus-core/src/handler/handler.ts:20

Implemented by a class to indicate it acts as a handler for a given message

Type Parameters ​

Type ParameterDefault type
TMessage extends MessageBaseMessageBase
TMessageAttributes extends MessageAttributesMessageAttributes

Properties ​

PropertyTypeDescriptionDefined in
messageTypeMessageDeclaration<TMessage & Message>The type of message the class handles: a message class, or a definition from defineCommand or defineEvent. Define it as a getter (get messageType() { return MyEvent }) so that withHandler() can read it without constructing the handler. A class field is only readable from an instance, so the handler is constructed without its dependencies when it's registered.packages/bus-core/src/handler/handler.ts:30

Methods ​

handle() ​

ts
handle(
   message, 
   attributes, 
   context
): unknown;

Defined in: packages/bus-core/src/handler/handler.ts:39

A function that is called each time a message of messageType is received

Parameters ​

ParameterTypeDescription
messageTMessageThe message read from the bus
attributesTMessageAttributesAttributes of the message read from the bus
contextHandlerContextSends, publishes, fails or returns messages through the bus that received the message

Returns ​

unknown

Anything. A returned promise is awaited, and the value it resolves to is ignored

Released under the MIT License.