Skip to content

Instantly share code, notes, and snippets.

@akehoyayoi
Created June 2, 2021 06:34
Show Gist options
  • Save akehoyayoi/9b38aec36ca1f6478fab0a0baea6bf24 to your computer and use it in GitHub Desktop.
Save akehoyayoi/9b38aec36ca1f6478fab0a0baea6bf24 to your computer and use it in GitHub Desktop.
PubSub typescript sample
// "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