@pluralsight/gcp-pubsub-lite
Advanced tools
Comparing version 1.0.13 to 1.0.14
{ | ||
"name": "@pluralsight/gcp-pubsub-lite", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "Convenience wrapper for GCP Pub/Sub", | ||
@@ -5,0 +5,0 @@ "main": "src/pubsub.js", |
@@ -23,21 +23,21 @@ # gcp-pubsub-lite | ||
const gcpPubSub = require("@google-cloud/pubsub"); | ||
const pubsub = require("@pluralsight/gcp-pubsub-lite"); | ||
const psLite = require("@pluralsight/gcp-pubsub-lite"); | ||
const {GCP_PROJECT_ID: gcpProjectId} = process.env; | ||
pubsub.setup(gcpPubSub, gcpProjectId); | ||
psLite.setup(gcpPubSub, gcpProjectId); | ||
const topicName = "topicName"; | ||
await pubsub.createTopic(topicName); | ||
await psLite.createTopic(topicName); // idempotent | ||
const subName = "subName"; | ||
await pubsub.createSubscription(topicName, subName); | ||
await psLite.createSubscription(topicName, subName); // idempotent | ||
const messageData = {test: true, count: 5, data: "foobar", pi: 3.14}; | ||
await pubsub.publishJson(topicName, messageData); | ||
let isPolling = true | ||
await psLite.publishJson(topicName, messageData); | ||
let isPolling = true; | ||
while (isPolling) { | ||
let envelopes = [] | ||
envelopes = await pubsub.pull(subName, 1); | ||
const envelopes = await psLite.pull(subName, 1); | ||
if (!envelopes.length) { | ||
// wait 500ms and try again | ||
await new Promise(resolve => setTimeout(resolve, 500)); | ||
@@ -48,10 +48,11 @@ continue; | ||
const {message, ackId} = envelope; | ||
const copyOfMessageData = pubsub.jsonifyMessageData(message); | ||
const copyOfMessageData = psLite.jsonifyMessageData(message); | ||
console.log("message", copyOfMessageData); | ||
await pubsub.acknowledge(subName, [ackId]); | ||
console.log("message contains:", copyOfMessageData); | ||
await psLite.acknowledge(subName, [ackId]); | ||
isPolling = false; | ||
} | ||
await Promise.all([pubsub.deleteSubscription(subName), | ||
pubsub.deleteTopic(topicName)]); | ||
await Promise.all([psLite.deleteSubscription(subName), | ||
psLite.deleteTopic(topicName)]); | ||
@@ -58,0 +59,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26445
315