---
url: https://node-ts.github.io/bus/api/bus-messages/functions/messageAttributes.md
---
[API reference](../../index.md) / [@node-ts/bus-messages](../index.md) / messageAttributes

# Function: messageAttributes()

```ts
function messageAttributes<AttributesType, StickyAttributesType>(...input): MessageAttributes<AttributesType, StickyAttributesType>;
```

Defined in: [packages/bus-messages/src/message-attributes.ts:75](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-messages/src/message-attributes.ts#L75)

Creates `MessageAttributes` with `attributes` and `stickyAttributes` defaulted to `{}`, so a test can call a
handler directly without spelling out empty attributes. Handlers still receive both fields, so they read them
without `?.`.

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `AttributesType` *extends* [`MessageAttributeMap`](../interfaces/MessageAttributeMap.md) | `object` |
| `StickyAttributesType` *extends* [`MessageAttributeMap`](../interfaces/MessageAttributeMap.md) | `object` |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| ...`input` | `object` *extends* `AttributesType` & `StickyAttributesType` ? \[[`MessageAttributesInput`](../type-aliases/MessageAttributesInput.md)<`AttributesType`, `StickyAttributesType`>] : \[[`MessageAttributesInput`](../type-aliases/MessageAttributesInput.md)<`AttributesType`, `StickyAttributesType`>] | the correlation id and the attributes to set |

## Returns

[`MessageAttributes`](../interfaces/MessageAttributes.md)<`AttributesType`, `StickyAttributesType`>

message attributes with any missing `attributes` or `stickyAttributes` set to `{}`

## Examples

```ts
await placeOrderHandler.messageHandler(PlaceOrder({ orderId: '1' }), messageAttributes(), fakeContext)
```

```ts
messageAttributes({ correlationId: 'c', attributes: { tenantId: 'a' } })
```
