1
votes

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

2
Did you solve your question? I'm trying to do the same and can't figure out how to.Lorenzo Petroli

2 Answers

1
votes

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.

0
votes

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));
}