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.
1
await bus.send(
2
new ChargeCreditCard(),
3
{
4
attributes: {
5
ip: '229.40.202.156',
6
attempt: 0,
7
automatic: true
8
}
9
}
10
)
Copied!
Attributes can be accessed as the second parameter of the handler.
1
import { MessageAttributes } from '@node-ts/bus-messages'
2
​
3
await Bus.configure()
4
.withHandler(
5
ChargeCreditCard,
6
async (_: ChargeCreditCard, { attributes }: MessageAttributes) => console.log(attributes)
7
)
8
.initialize()
Copied!
Copy link