Socket
Book a DemoInstallSign in
Socket

@getcircuit/pubsub

Package Overview
Dependencies
Maintainers
19
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@getcircuit/pubsub

latest
npmnpm
Version
1.0.0
Version published
Maintainers
19
Created
Source

@getcircuit/pubsub

Classes

This library exposes a set of utility classes to interact with Google's Pub/Sub.

PubSubPublisher

This class is responsible for setting up a publisher to publish messages to a specific topic.

The topic must already exist.

StreamingSubscriber

This class is responsible for setting up a StreamingPull subscription to a specific Pub/Sub subscription.

The Pub/Sub subscription must already exist.

This is the preferred class for setting up subscribers as it already handles adding Tracing attributes to every received message and creates a span for each automatically, as well as calls a callback for each message.

This class keeps an open connection that immediately receives and processes new messages when available.

PollingSubscriber

This class is responsible for setting up a Pull subscription to a specific Pub/Sub subscription.

The Pub/Sub subscription must already exist.

Contrary to the StreamingSubscriber class, this class does not add the Tracing attributes of the messages to each span, because it pulls messages in batches and on demand.

Temporary subscriptions

There are 4 functions that are able to create temporary subscriptions for helping in local development:

  • getTemporaryStreamingSubscriberFromSubscription
    • As the name implies, creates a new StreamingSubscriber pointing to a temporary subscription (1 day expiry time), from the topic that another subscription points to. This is useful if you only have the subscription name and not the topic name.
  • getTemporaryStreamingSubscriberFromTopic
    • This is the same as the previous one, but it uses the topic name directly.
  • getTemporaryPollingSubscriberFromSubscription
    • As the name implies, creates a new PollingSubscriber pointing to a temporary subscription (1 day expiry time), from the topic that another subscription points to. This is useful if you only have the subscription name and not the topic name.
  • getTemporaryPollingSubscriberFromTopic
    • This is the same as the previous one, but it uses the topic name directly.

Testing utilities

There are 2 testing utilities provided by the library:

  • mockPubSubFromFirebaseApp
    • It uses the provided Firebase Admin App to infer the current projectId and creates and returns one instance of the PubSubPublisher, one of the StreamingSubscriber and one of the PollingSubscriber. They all share the same - random - topic names and subscription names, which is useful to ensure tests can run concurrently for Pub/Sub. This function thus should only be ruen on an environemnt where the emulator is present
  • mockPubSub
    • The same as the above, but uses the provided projectId directly

FAQs

Package last updated on 29 Jan 2024

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