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.10
  • 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, or pinning to a previous version. We will keep this library up-to-date to be compatible with recent versions of the official library. Currently we support @google-cloud/pubsub versions 1.4.1+.

The official Google library, while full-featured, requires focused reading to understand and boilerplate to accomplish simple tasks. It uses an OO approach where the same things can be accomplished with different classes, in slightly different ways. By contrast, gcp-pubsub-lite uses simple, easy to use, functions. For example, gcp-pubsub-lite 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;
pubsub.setup(gcpPubSub, gcpProjectId);

const topicName = "topicName";
await pubsub.createTopic(topicName);

const subName = "subName";
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)]);

Contributions

Pull Requests are welcome.

Keywords

FAQs

Package last updated on 11 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