-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement pubsub * feat: add the module * chore: simplify * chore: bump libs * chore: remove emulator host * chore: remove falsy this. * chore: lowercase ro * chore: update default config * chore: remove options * chore: version bump * refactor: update docs links * chore: bump libs * chore: PubSub naming * chore: update messages * chore: filenames * chore: lowercase anchor * chore: remove publisher dev script * chore: 's * chore: 's
- Loading branch information
1 parent
8472f84
commit 7ce4748
Showing
14 changed files
with
1,079 additions
and
15,010 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { PubSub } from "@google-cloud/pubsub"; | ||
|
||
const pubSub = new PubSub({ | ||
projectId: process.env.PUBSUB_PROJECT_ID, | ||
keyFile: process.env.PUBSUB_KEY_FILE | ||
}); | ||
|
||
async function run() { | ||
const topicName = process.env.PUBSUB_TOPIC_NAME; | ||
const topic = pubSub.topic(topicName!); | ||
|
||
const topicExists = (await topic.exists())[0]; | ||
if (!topicExists) throw new Error(`Topic '${topicName}' does not exist.`); | ||
|
||
const subscriptionName = process.env.PUBSUB_SUBSCRIPTION_NAME!; | ||
const subscription = topic.subscription(subscriptionName); | ||
const subscriptionExists = (await subscription.exists())[0]; | ||
if (!subscriptionExists) throw new Error(`Subscription '${subscriptionName}' does not exist.`); | ||
|
||
subscription.on("message", (message) => { | ||
console.log(message.id); | ||
console.log(message.data.toString()); | ||
console.log(message.attributes); | ||
|
||
message.ack(); | ||
}); | ||
} | ||
|
||
run(); |
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
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
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
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
Oops, something went wrong.