Skip to content

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 ​

ts
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() ​

ts
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 ​

ParameterTypeDescription
eventTEventThe 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() ​

ts
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 ​

ParameterTypeDescription
commandTCommandThe 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>

Released under the MIT License.