---
url: https://node-ts.github.io/bus/api/bus-core/type-aliases/FunctionHandler.md
---
[API reference](../../index.md) / [@node-ts/bus-core](../index.md) / 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](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/handler/handler.ts#L56)

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`](../../bus-messages/interfaces/MessageAttributes.md) | [`MessageAttributes`](../../bus-messages/interfaces/MessageAttributes.md) |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | `TMessage` | The message read from the bus |
| `attributes` | `TMessageAttributes` | Attributes of the message read from the bus |
| `context` | [`HandlerContext`](../interfaces/HandlerContext.md) | 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))
```
