API reference / @node-ts/bus-core / FunctionHandler
Type Alias: FunctionHandler<TMessage, TMessageAttributes>
ts
type FunctionHandler<TMessage, TMessageAttributes> = (message, attributes, context) => unknown;Defined in: packages/bus-core/src/handler/handler.ts:56
A function that is called each time a message of the type it's registered for is received
Type Parameters
| Type Parameter | Default type |
|---|---|
TMessage | - |
TMessageAttributes extends MessageAttributes | MessageAttributes |
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
Example
ts
const placeOrderHandler: FunctionHandler<PlaceOrder> = async (message, _attributes, ctx) =>
ctx.publish(new OrderPlaced(message.orderId))