API reference / @node-ts/bus-core / BusSender
Interface: BusSender
Defined in: packages/bus-core/src/handler/bus-sender.ts:17
Sends commands and publishes events. BusInstance implements it, and so does the HandlerContext that's passed to every handler, so code that only needs to send messages can depend on this interface and be given either one, or a plain object in a test.
Example
const placeOrder = async (sender: BusSender, orderId: string) =>
sender.send(new PlaceOrder(orderId))
// In production
await placeOrder(bus, '1')
// In a test
const sent: Command[] = []
await placeOrder({ send: async c => { sent.push(c) }, publish: async () => {} }, '1')Extended by
Methods
publish()
publish<TEvent>(event, messageAttributes?): Promise<void>;Defined in: packages/bus-core/src/handler/bus-sender.ts:37
Publishes an event to the transport. Inside a handler, the event is buffered and only published once the handler resolves, and is dropped if the handler fails.
Type Parameters
| Type Parameter |
|---|
TEvent extends Event |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | TEvent | The event to publish |
messageAttributes? | Partial<MessageAttributes<MessageAttributeMap, MessageAttributeMap>> | Attributes to attach to the outgoing message. The correlationId and stickyAttributes of the message being handled are added when published from a handler. |
Returns
Promise<void>
send()
send<TCommand>(command, messageAttributes?): Promise<void>;Defined in: packages/bus-core/src/handler/bus-sender.ts:25
Sends a command to the transport. Inside a handler, the command is buffered and only sent once the handler resolves, and is dropped if the handler fails.
Type Parameters
| Type Parameter |
|---|
TCommand extends Command |
Parameters
| Parameter | Type | Description |
|---|---|---|
command | TCommand | The command to send |
messageAttributes? | Partial<MessageAttributes<MessageAttributeMap, MessageAttributeMap>> | Attributes to attach to the outgoing message. The correlationId and stickyAttributes of the message being handled are added when sent from a handler. |
Returns
Promise<void>