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 Parameter | Default type |
|---|---|
TMessage extends MessageBase | MessageBase |
TMessageAttributes extends MessageAttributes | MessageAttributes |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
messageType | MessageDeclaration<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
| Parameter | Type | Description |
|---|---|---|
message | TMessage | The message read from the bus |
attributes | TMessageAttributes | Attributes of the message read from the bus |
context | HandlerContext | Sends, 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