Skip to main content
zerotal

Documentation


Documentation / @zerotal/notifications / BroadcastMessage

Class: BroadcastMessage

Defined in: notifications/src/BroadcastMessage.ts:10

The broadcastable representation of a notification, returned from Notification.toBroadcast(). Wraps the data payload plus optional queue routing.

Example

toBroadcast() {
  return new BroadcastMessage({ invoiceId: this.invoice.id, amount: this.invoice.amount });
}

Constructors

Constructor

new BroadcastMessage(data): BroadcastMessage

Defined in: notifications/src/BroadcastMessage.ts:14

Parameters

data

Record<string, unknown>

Returns

BroadcastMessage

Properties

queue

queue: string | undefined = undefined

Defined in: notifications/src/BroadcastMessage.ts:12

Queue to deliver this broadcast on. Unset means deliver inline.


data

readonly data: Record<string, unknown>

Defined in: notifications/src/BroadcastMessage.ts:14

Methods

onQueue()

onQueue(queue): this

Defined in: notifications/src/BroadcastMessage.ts:28

Deliver this broadcast from a queue rather than inline.

Worth doing when the broadcast fans out to many connections and the request should not wait for it. The trade is latency: a queued broadcast arrives whenever a worker picks it up.

Parameters

queue

string

Returns

this

Example

toBroadcast() {
  return new BroadcastMessage({ id: this.report.id }).onQueue("broadcasts");
}