Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pluralsight/gcp-pubsub-lite

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pluralsight/gcp-pubsub-lite

Convenience wrapper for GCP Pub/Sub

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
increased by1300%
Maintainers
1
Weekly downloads
 
Created
Source

gcp-pubsub-lite

npm version GitHub Workflow Status

This is a convenience library/wrapper for the official GCP Pub/Sub library. You supply our wrapper with the official GCP Pub/Sub library so you control which version you want to use. This way, our library will not block you from applying e.g. the latest security updates. We will keep this library up-to-date to be compatible with recent versions of the official library. As of this writing, @google-cloud/pubsub versions 1.4.1+ are supported.

The official library, while full-featured, requires some deeper understanding and boilerplate to accomplish common tasks. gcp-pubsub-lite, for example, enables simple subscription polling and sending/receiving JSON data as shown below.

Installation

npm i @google-cloud/pubsub @pluralsight/gcp-pubsub-lite

Usage Example

const gcpPubSub = require("@google-cloud/pubsub");
const pubsub = require("@pluralsight/gcp-pubsub-lite");

const {GCP_PROJECT_ID: gcpProjectId} = process.env;

const topicName = "topicName";
const subName = "subName";
pubsub.setup(gcpPubSub, gcpProjectId);

await pubsub.createTopic(topicName);
await pubsub.createSubscription(topicName, subName);

const messageData = {test: true, count: 5, data: "foobar", pi: 3.14};
await pubsub.publishJson(topicName, messageData);
let isPolling = true

while (isPolling) {
    let envelopes = []
    envelopes = await pubsub.pull(subName, 1);
    if (!envelopes.length) {
      await new Promise(resolve => setTimeout(resolve, 500));
      continue;
    }
    const [envelope] = envelopes;
    const {message, ackId} = envelope;
    const copyOfMessageData = pubsub.jsonifyMessageData(message);

    console.log("message", copyOfMessageData);
    await pubsub.acknowledge(subName, [ackId]);
}

await Promise.all([pubsub.deleteSubscription(subName),
                   pubsub.deleteTopic(topicName)]);

Keywords

FAQs

Package last updated on 10 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc