
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@pluralsight/gcp-pubsub-lite
Advanced tools
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+ and node.js v12+.
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.
# npm
npm i @google-cloud/pubsub @pluralsight/gcp-pubsub-lite
# yarn
yarn add @google-cloud/pubsub @pluralsight/gcp-pubsub-lite
const gcpPubSub = require("@google-cloud/pubsub");
const psLite = require("@pluralsight/gcp-pubsub-lite");
const {GCP_PROJECT_ID: gcpProjectId} = process.env;
psLite.setup(gcpPubSub, gcpProjectId);
const topicName = "topicName";
await psLite.createTopic(topicName); // idempotent
const subName = "subName";
await psLite.createSubscription(topicName, subName); // idempotent
const messageData = {test: true, count: 5, data: "foobar", pi: 3.14};
await psLite.publishJson(topicName, messageData);
let isPolling = true;
while (isPolling) {
const envelopes = await psLite.pull(subName, 1);
if (!envelopes.length) {
// wait 500ms and try again
await new Promise(resolve => setTimeout(resolve, 500));
continue;
}
const [envelope] = envelopes;
const {message, ackId} = envelope;
const copyOfMessageData = psLite.jsonifyMessageData(message);
console.log("message contains:", copyOfMessageData);
await psLite.acknowledge(subName, [ackId]);
isPolling = false;
}
await Promise.all([psLite.deleteSubscription(subName),
psLite.deleteTopic(topicName)]);
Sets up the library. This must be called before other functions in this library.
Promise.<Array.<object>>
Creates a Pub/Sub Topic. Idempotent.
Promise.<string>
Deletes a Pub/Sub Topic.
Promise.<object>
Create a Pub/Sub subscription. Idempotent.
Promise
Delete a Pub/Sub subscription.
Promise.<object>
publish a message to a topic
Promise.<object>
publish a json message to a topic
Promise.<Array.<object>>
pull messages from a topic
Promise
acknowledge completion of a pulled message
Promise.<boolean>
Whether or not a subscription exists
*
Takes a JSON pub/sub message and returns the data part as a native javascript value
Promise.<boolean>
Checks whether a topic exists
string
inspects this module, get what gcp project is being used
PublisherClient
inspects this module, get internal google pub/sub publisher client
SubscriberClient
inspects this module, get internal google pub/sub subscriber client
Promise.<Array.<PublishResponse>>
Publish many messages to a topic
Promise.<Array.<PublishResponse>>
Publish many json messages to a topic
Sets up the library. This must be called before other functions in this library.
Kind: global function
Param | Type | Description |
---|---|---|
gcpPubSub | object | Google Pub/Sub Library from require("@google-cloud/pubsub") |
projectId | string | GCP project id |
Promise.<Array.<object>>
Creates a Pub/Sub Topic. Idempotent.
Kind: global function
Returns: Promise.<Array.<object>>
- returns response from Google library's topic.get(): [Topic, apiResponse], see https://googleapis.dev/nodejs/pubsub/latest/global.html#GetTopicCallback
Param | Type | Description |
---|---|---|
topicName | string | Name of topic to create |
Promise.<string>
Deletes a Pub/Sub Topic.
Kind: global function
Returns: Promise.<string>
- returns deleted topicName
Param | Type | Description |
---|---|---|
topicName | string | Name of topic to delete |
Promise.<object>
Create a Pub/Sub subscription. Idempotent.
Kind: global function
Returns: Promise.<object>
- returns {success: true}
Param | Type | Default | Description |
---|---|---|---|
topicName | string | Name of topic to which the subscription attaches. Topic must exist. | |
subscriptionName | string | Name of subscription to create | |
[options] | object | {} | Options passed to GCP Lib's subscriber.createSubscription(). see https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html |
Promise
Delete a Pub/Sub subscription.
Kind: global function
Param | Type | Description |
---|---|---|
subscriptionName | string | Name of subscription to delete |
Promise.<object>
publish a message to a topic
Kind: global function
Returns: Promise.<object>
- Pub/Sub PublishResponse object, see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PublishResponse
Param | Type | Description |
---|---|---|
topicName | string | Name of topic to publish the message to |
message | PubsubMessage | Message object, see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PubsubMessage |
message.data | buffer | object | string | Message data, must be compatible with Buffer.from() https://nodejs.org/docs/latest-v12.x/api/buffer.html |
Promise.<object>
publish a json message to a topic
Kind: global function
Returns: Promise.<object>
- Pub/Sub PublishResponse object, see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PublishResponse
Param | Type | Description |
---|---|---|
topicName | string | Name of topic to publish the message to |
message | * | javascript data to publish. Must be compatible with JSON.stringify() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify |
Promise.<Array.<object>>
pull messages from a topic
Kind: global function
Returns: Promise.<Array.<object>>
- receivedMessages, see: https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PullResponse
Param | Type | Default | Description |
---|---|---|---|
subscriptionName | string | Name of subscription | |
[maxMessages] | number | 1 | Maximum number of messages to pull |
[returnImmediately] | boolean | true | Whether or not to return immediately. If false, waits about 5 seconds then the promise rejects |
Promise
acknowledge completion of a pulled message
Kind: global function
Param | Type | Description |
---|---|---|
subscriptionName | string | Name of subscription |
ackIds | Array.<string> | The acknowledgment ID for the messages being acknowledged that was returned by the Pub/Sub system in the Pull response. Must not be empty. |
Promise.<boolean>
Whether or not a subscription exists
Kind: global function
Param | Type | Description |
---|---|---|
subscriptionName | string | Name of subscription |
*
Takes a JSON pub/sub message and returns the data part as a native javascript value
Kind: global function
Returns: *
- native javascript value
Param | Type | Description |
---|---|---|
message | receivedMessage | https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.ReceivedMessage |
Promise.<boolean>
Checks whether a topic exists
Kind: global function
Param | Type | Description |
---|---|---|
topicName | string | name of the topic to check |
string
inspects this module, get what gcp project is being used
PublisherClient
inspects this module, get internal google pub/sub publisher client
Kind: global function
Returns: PublisherClient
- https://googleapis.dev/nodejs/pubsub/latest/v1.PublisherClient.html
SubscriberClient
inspects this module, get internal google pub/sub subscriber client
Kind: global function
Returns: SubscriberClient
- https://googleapis.dev/nodejs/pubsub/latest/v1.SubscriberClient.html
Promise.<Array.<PublishResponse>>
Publish many messages to a topic
Kind: global function
Returns: Promise.<Array.<PublishResponse>>
- Pub/Sub PublishResponse objects, see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PublishResponse
Param | Type | Description |
---|---|---|
topicName | string | Name of the topic to publish to |
messages | Array.<PubsubMessage> | Message objects to publish, see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PubsubMessage |
Promise.<Array.<PublishResponse>>
Publish many json messages to a topic
Kind: global function
Returns: Promise.<Array.<PublishResponse>>
- Pub/Sub PublishResponse objects, see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PublishResponse
Param | Type | Description |
---|---|---|
topicName | string | Name of the topic to publish to |
messages | Array.<object> | message objects to publish. data value be compatible with JSON.stringify() see https://googleapis.dev/nodejs/pubsub/latest/google.pubsub.v1.html#.PubsubMessage |
Pull Requests are welcome.
FAQs
Convenience wrapper for GCP Pub/Sub
The npm package @pluralsight/gcp-pubsub-lite receives a total of 3 weekly downloads. As such, @pluralsight/gcp-pubsub-lite popularity was classified as not popular.
We found that @pluralsight/gcp-pubsub-lite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.