-
Notifications
You must be signed in to change notification settings - Fork 1
/
pubsub.js
40 lines (31 loc) · 976 Bytes
/
pubsub.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// import * as pubsub from "@google-cloud/pubsub";
const pubsub = () => {}
const serviceAccountJson = JSON.parse(process.env.SERVICE_ACCOUNT_JSON);
const config = {
keyFilename: serviceAccountJson
};
let client = pubsub(config);
export async function topic(args) {
const [topic, response] = await client.topic(args.name).get();
return topic;
}
export async function createTopic(args) {
const [topic, response] = await client.topic(args.name).create();
}
export function getTopicName(topicName) {
return topicName.replace("membrane-driver-", "");
}
export function getSubscriptionName(topicName) {
return "membrane-driver-" + topicName;
}
export async function createSubscription(name, topic, pushEndpoint) {
const [subscription, response] = await client.subscribe(topic, name, {
pushEndpoint
});
}
export async function deleteSubscription(name, topic) {
const [response] = await client
.topic(topic)
.subscription(name)
.delete();
}