Łukasz Patecki
Łukasz Patecki

Reputation: 43

Trigger a PubSub message from Cloud Functions

Firebase docs mention a straightforward way of subscribing to a pubSub topic.

Does Cloud Functions or Firebase Admin SDK provide a way to publish pubSub events or we are limited to what is described in Google Cloud Platform docs: https://cloud.google.com/pubsub/docs/publisher#pubsub-publish-message-nodejs

Upvotes: 1

Views: 2291

Answers (2)

Daniel Tomas
Daniel Tomas

Reputation: 1

Hope it can help, although it's late. Here is a clear explanation (by Google itself) on how to use it https://cloud.google.com/pubsub/docs/publisher and here is an example https://github.com/googleapis/nodejs-pubsub/blob/master/samples/publishMessageWithCustomAttributes.js

TLDR Here is my condensed version

public static publishMessage(data: unknown, topicName: string): Observable<void> {
        const pubSubClient: PubSub = new PubSub();
        const dataBuffer: Buffer = Buffer.from(JSON.stringify(data));
        return from(pubSubClient.topic(topicName).publish(dataBuffer));
}

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317750

The Firebase Admin SDK, for many products, is just a convenience wrapper around the underlying Cloud SDKs. For pubsub, however, it provides no such wrapper. You'll have to use the Google Cloud SDK directly if you want to send pubsub messages.

Upvotes: 2

Related Questions