Created
June 2, 2021 06:34
-
-
Save akehoyayoi/9b38aec36ca1f6478fab0a0baea6bf24 to your computer and use it in GitHub Desktop.
PubSub typescript sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "dependencies": { | |
// "@google-cloud/pubsub": "^2.3.0", | |
// "firebase-admin": "^9.8.0", | |
// "firebase-functions": "^3.14.1" | |
// }, | |
import * as functions from "firebase-functions"; | |
import { PubSub } from '@google-cloud/pubsub'; | |
const client = new PubSub(); | |
// // Start writing Firebase Functions | |
// // https://firebase.google.com/docs/functions/typescript | |
// | |
export const helloPubSub = functions | |
.pubsub | |
.topic('test') | |
.onPublish((message) => { | |
console.log(message.json); | |
}); | |
export const helloAPI = functions | |
.https | |
.onRequest((request, response) => { | |
client.topic('test').publish(Buffer.from('{"name":"Hello"}')); | |
response.send('called'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment