📘
@node-test/bus
  • @node-ts/bus
  • Getting started
    • Installation
    • Handling messages
    • Shutting down cleanly
  • Reference
    • Bus
    • BusConfiguration
    • BusInstance
  • Getting help
  • Guide
    • Messages
      • Events
      • Commands
      • System messages
    • Message attributes
      • Correlation id
      • Attributes
      • Sticky attributes
    • Workflows
      • Creating a workflow
      • Starting
      • Handling
      • State
      • Completing
      • Example
    • Transports
      • RabbitMQ
      • Amazon SQS
      • Redis
      • Custom transports
    • Persistence
      • Postgres
      • MongoDB
      • Creating a persistence
    • Serializers
      • Class serializer
    • Loggers
      • Custom loggers
    • Middleware
    • Lifecycle hooks
    • Retry Strategies
    • Dependency injection
    • Long running processes
Powered by GitBook
On this page

Was this helpful?

  1. Guide
  2. Message attributes

Attributes

Arbitrary attributes can be sent with each message. Attributes support string | number | boolean values. These can be provided by using the attributes property when sending a message.

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

Attributes can be accessed as the second parameter of the handler.

import { MessageAttributes } from '@node-ts/bus-messages'

await Bus.configure()
  .withHandler(
    ChargeCreditCard,
    async (_: ChargeCreditCard, { attributes }: MessageAttributes) => console.log(attributes)
  )
  .initialize()
PreviousCorrelation idNextSticky attributes

Last updated 3 years ago

Was this helpful?