Inherits from
Events
channel and subscriptionOptions property.
error, channel and subscriptionOptions property.
channel property.
Methods
channelName. Do not expect a response from the back end broker.
The channelName argument must be a string.
The data argument can be any JSON-compatible object/array or primitive.
channelName. Expect a response from the broker.
The channelName argument must be a string.
The data argument can be any JSON-compatible object/array or primitive.
This method returns a Promise which will be rejected if the operation fails.
The promise will resolve once the server has processed the publish action.
To consume a channel, it is recommended to use a for-await-of loop like this:
for await (
let data of exchange.channel('myChannel')
) {
// Consume channel data...
}
Because the agServer.exchange.subscribe(...) method returns an AGChannel instance, you can also consume it directly like this:
for await (
let data of exchange.subscribe('myChannel')
) {
// Consume channel data...
}
Note that agServer.exchange.subscribe(...) can be called multiple times for the same channel; if already subscribed, the method will only return the channel.
subscribe(channelName) again at a later time.
exchange.subscribe(...) in that it will not try to subscribe to that channel.
The returned channel will be inactive initially.
You can call channel.subscribe() later to activate that channel when required.
for-await-of loops (for the channelName channel and all of its listeners) to break after they have finished iterating over their current backlogs of events.
closeChannel(channelName) except that it only closes the main channel (output) stream. Listener consumers on the channel will not be affected.
closeChannel(channelName) except that it only closes listener streams on the channel. The main channel output stream will not be affected.
To close specific listeners (by eventName) on a specific channel, it's recommended that you use the AGChannel API.
for-await-of loops for all channels (and all of their listeners) to break after they have finished consuming their respective backlogs of events.
for-await-of loops for the channelName channel (and all of its listeners) to break immediately. This will reset the backpressure for that channel (and all of its event listeners) to 0.
killChannel(channelName) except that it only kills the main channel (output) stream. Listener consumers on the channel will not be affected.
killChannel(channelName) except that it only kills listener streams on the channel. The main channel output stream will not be affected.
To kill specific listeners (by eventName) on a specific channel, it's recommended that you use the AGChannel API.
for-await-of loops for all channels (and all of of their listeners) to break immediately. This will reset the aggregate backpressure for all channels (and all of their event listeners) to 0.
killAllChannels() except that it only kills channel output streams; channel event listeners will not be affected. This will reset the aggregate backpressure for all channel output streams to 0.
killAllChannels() except that it only kills channel listener streams; channel output streams will not be affected. This will reset the aggregate backpressure for all channel listener streams to 0.
includePending is true, pending subscriptions will also be included in the list.
includePending is true, pending subscriptions will also be included in the list.
listener streams on the exchange instance.
eventName listener stream on the exchange instance. The aggregate backpressure represents the highest backpressure of all consumers for that listener.
channel streams on the exchange instance.
Stream management methods
These methods should only be used for advanced use cases when you need more control over stream management; for example, when you want to break out of a specific consumer loop without affecting any other consumer.
These methods can also be useful to check that consumers are being cleaned up properly and to selectively kill specific consumers which are causing backpressure to build up.
For most use cases, you should try to stick to the methods in the table above as it will lead to cleaner logic.
id and backpressure property.
id and backpressure property.
for-await-of loop to break immediately.
id and backpressure property.
id and backpressure property.
id and backpressure property.
id and backpressure property.
for-await-of loop to break immediately.
for-await-of loop to break immediately.