Skip to content

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 ParameterDefault type
TMessage-
TMessageAttributes extends MessageAttributesMessageAttributes

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

Example ​

ts
const placeOrderHandler: FunctionHandler<PlaceOrder> = async (message, _attributes, ctx) =>
  ctx.publish(new OrderPlaced(message.orderId))

Released under the MIT License.