---
url: https://node-ts.github.io/bus/guide/message-attributes/attributes.md
description: Send values with a message for its receiver, and type them in the handler.
---

# Attributes

::: tip Looking for the correlation id?
This address used to be the correlation id page, which is now [Correlation id](/guide/message-attributes/correlation-id).
:::

Any values can be sent with a message as attributes. Unlike [sticky attributes](/guide/message-attributes/sticky-attributes), they're only for the receiver of that message, and aren't copied to the messages it sends. This page shows how to send and read them.

Attribute values can be strings, numbers or booleans. Set them with `attributes` when sending or publishing:

```ts
await bus.send(new ChargeCreditCard('tok_visa', 1200), {
  attributes: {
    ip: '229.40.202.156',
    attempt: 0,
    automatic: true
  }
})
```

Handlers receive them in the `attributes` of their second argument. To type them, give the attributes type as the second type argument of `handlerFor`, after the message type:

```ts
type ChargeAttributes = MessageAttributes<{
  ip: string
  attempt: number
  automatic: boolean
}>

export const chargeCreditCardHandler = handlerFor<
  ChargeCreditCard,
  ChargeAttributes
>(ChargeCreditCard, async (_command, { attributes }) =>
  console.log('Charge requested', { ip: attributes.ip })
)

const paymentsBus = Bus.configure()
  .withMessageTypes(messageTypes)
  .withHandler(chargeCreditCardHandler)
  .build()
```

The attributes aren't validated when a message is received, so the type is a promise that the sender has to keep.

## See also

* [Sticky attributes](/guide/message-attributes/sticky-attributes)
* [Correlation id](/guide/message-attributes/correlation-id)
