subscribe

View as Markdown

subscribe

  • subscribe(channels): Promise<void>

List of channels for which you want to receive messages.

Note that the subscribe function is idempotent, and calling it again with a different set of channels will not unsubscribe you from the old ones. To unsubscribe, use unsubscribe.

Parameters

NameTypeDescription
channelsstring | string[]The channels to subscribe to, either in the form of a string (for one channel) or an array of strings.

Returns

Promise<void>

Example

1const pubSubClient = new PubSub.Client({
2 project: "<project-id>",
3 token: "<api-token>",
4});
5
6await pubSubClient.subscribe("my-channel");
7await pubSubClient.subscribe(["chan-2", "chan-3"]);