---
url: https://node-ts.github.io/bus/guide/message-attributes/sticky-attributes.md
description: >-
  Attributes that are copied to every message sent while handling a message, and
  to the messages after them.
---

# Sticky attributes

Sticky attributes are like [attributes](/guide/message-attributes/attributes), except that they're copied to every message sent or published while the message is handled, and from those to the next, all the way down the flow. This page shows how to send and read them.

Use them for context that the whole flow needs, such as a tenant id or the user that started it. Set them with `stickyAttributes`:

```ts
await bus.send(new ChargeCreditCard('tok_visa', 1200), {
  stickyAttributes: {
    tenantId: 'acme',
    requestedBy: 'user-42'
  }
})
```

Handlers receive them in the `stickyAttributes` of their second argument. Type them with the second type parameter of `MessageAttributes`:

```ts
type TenantAttributes = MessageAttributes<
  {},
  { tenantId: string; requestedBy: string }
>

export const chargeCreditCardHandler = handlerFor<
  ChargeCreditCard,
  TenantAttributes
>(ChargeCreditCard, async (command, { stickyAttributes }, ctx) => {
  console.log('Charging card', { tenantId: stickyAttributes.tenantId })
  // CreditCardCharged carries the same sticky attributes
  await ctx.publish(
    new CreditCardCharged(command.creditCardToken, command.amount, new Date())
  )
})
```

[Workflows](/guide/workflows) use a sticky attribute to route replies back to the workflow that sent a command.

## See also

* [Correlation id](/guide/message-attributes/correlation-id), which propagates the same way
* [Handling](/guide/workflows/handling) in workflows
