How to use the @google-cloud/pubsub.PubSub function in @google-cloud/pubsub

To help you get started, we’ve selected a few @google-cloud/pubsub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / fxa / packages / fxa-event-broker / bin / worker.ts View on Github external
async function main() {
  const capabilityService = new ClientCapabilityService(
    logger,
    Config.get('clientCapabilityFetch')
  );
  const webhookService = new ClientWebhookService(
    logger,
    Config.get('clientCapabilityFetch.refreshInterval'),
    db
  );
  const pubsub = new PubSub();

  // Extract region for SQS object
  const serviceNotificationQueueUrl = Config.get('serviceNotificationQueueUrl');
  const region = extractRegionFromUrl(serviceNotificationQueueUrl);
  if (!region) {
    logger.error('invalidServiceUrl', {
      message: 'Cant find region in service url',
      serviceNotificationQueueUrl
    });
    process.exit(8);
  }
  const metrics = new StatsD(Config.get('metrics'));
  const processor = new ServiceNotificationProcessor(
    logger,
    db,
    metrics,
github googleapis / nodejs-pubsub / samples / topics.js View on Github external
async function getTopicPolicy(topicName) {
  // [START pubsub_get_topic_policy]
  // Imports the Google Cloud client library
  const {PubSub} = require('@google-cloud/pubsub');

  // Creates a client
  const pubsub = new PubSub();

  /**
   * TODO(developer): Uncomment the following line to run the sample.
   */
  // const topicName = 'my-topic';

  // Retrieves the IAM policy for the topic
  const [policy] = await pubsub.topic(topicName).iam.getPolicy();
  console.log(`Policy for topic: %j.`, policy.bindings);

  // [END pubsub_get_topic_policy]
}
github googleapis / nodejs-pubsub / samples / topics.js View on Github external
async function publishBatchedMessages(
  topicName,
  data,
  maxMessages,
  maxWaitTime
) {
  // [START pubsub_publisher_batch_settings]
  // Imports the Google Cloud client library
  const {PubSub} = require('@google-cloud/pubsub');

  // Creates a client
  const pubsub = new PubSub();

  /**
   * TODO(developer): Uncomment the following lines to run the sample.
   */
  // const topicName = 'my-topic';
  // const data = JSON.stringify({ foo: 'bar' });
  // const maxMessages = 10;
  // const maxWaitTime = 10000;

  // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
  const dataBuffer = Buffer.from(data);

  const batchPublisher = pubsub.topic(topicName, {
    batching: {
      maxMessages: maxMessages,
      maxMilliseconds: maxWaitTime,
github googleapis / nodejs-dlp / samples / risk.js View on Github external
callingProjectId,
  tableProjectId,
  datasetId,
  tableId,
  topicId,
  subscriptionId,
  quasiIds
) {
  // [START dlp_k_anonymity]
  // Import the Google Cloud client libraries
  const DLP = require('@google-cloud/dlp');
  const {PubSub} = require('@google-cloud/pubsub');

  // Instantiates clients
  const dlp = new DLP.DlpServiceClient();
  const pubsub = new PubSub();

  // The project ID to run the API call under
  // const callingProjectId = process.env.GCLOUD_PROJECT;

  // The project ID the table is stored under
  // This may or (for public datasets) may not equal the calling project ID
  // const tableProjectId = process.env.GCLOUD_PROJECT;

  // The ID of the dataset to inspect, e.g. 'my_dataset'
  // const datasetId = 'my_dataset';

  // The ID of the table to inspect, e.g. 'my_table'
  // const tableId = 'my_table';

  // The name of the Pub/Sub topic to notify once the job completes
  // TODO(developer): create a Pub/Sub topic to use for this
github googleapis / nodejs-dlp / samples / inspect.js View on Github external
kind,
  topicId,
  subscriptionId,
  minLikelihood,
  maxFindings,
  infoTypes,
  customInfoTypes
) {
  // [START dlp_inspect_datastore]
  // Import the Google Cloud client libraries
  const DLP = require('@google-cloud/dlp');
  const {PubSub} = require('@google-cloud/pubsub');

  // Instantiates clients
  const dlp = new DLP.DlpServiceClient();
  const pubsub = new PubSub();

  // The project ID to run the API call under
  // const callingProjectId = process.env.GCLOUD_PROJECT;

  // The project ID the target Datastore is stored under
  // This may or may not equal the calling project ID
  // const dataProjectId = process.env.GCLOUD_PROJECT;

  // (Optional) The ID namespace of the Datastore document to inspect.
  // To ignore Datastore namespaces, set this to an empty string ('')
  // const namespaceId = '';

  // The kind of the Datastore entity to inspect.
  // const kind = 'Person';

  // The minimum likelihood required before returning a match
github GoogleCloudPlatform / node-red-contrib-google-cloud / tests / pubsub_in_node_spec.js View on Github external
describe('pubsub_in Node', () => {

    const pubsub = new PubSub();

    beforeEach((done) => {
        helper.startServer(done);
    });

    afterEach((done)=> {
        helper.unload();
        helper.stopServer(done);
    });

    it('receive pubsub message', (done) => {
        const flow = [
            {
                "id": "n1",
                "type": "google-cloud-pubsub in",
                "subscription": "node-red-subscription",
github firebase / firebase-tools / src / emulator / pubsubEmulator.ts View on Github external
constructor(private args: PubsubEmulatorArgs) {
    const { host, port } = this.getInfo();
    this.pubsub = new PubSub({
      apiEndpoint: `${host}:${port}`,
      projectId: this.args.projectId,
    });

    this.triggers = new Map();
    this.subscriptions = new Map();
  }
github golevelup / nestjs / packages / google-pubsub / src / google-pubsub.module.ts View on Github external
useFactory: async (config: GooglePubSubConfig): Promise => {
            const pubSub = new PubSub({ projectId: config.projectId });
            return pubSub;
          },
          inject: [GOOGLE_PUBSUB_CONFIG]
github axelspringer / graphql-google-pubsub / src / google-pubsub.ts View on Github external
constructor(
    config?,
    topic2SubName: Topic2SubName = topicName => `${topicName}-subscription`,
    commonMessageHandler: CommonMessageHandler = message => message,
    pubSubClient = new PubSub(config)
  ) {
    this.clientId2GoogleSubNameAndClientCallback = {};
    this.googleSubName2GoogleSubAndClientIds = {};
    this.currentClientId = 0;
    this.pubSubClient = pubSubClient;
    this.topic2SubName = topic2SubName;
    this.commonMessageHandler = commonMessageHandler;
  }
github firebase / extensions / firestore-counter / functions / lib / index.js View on Github external
exports.controller = functions.https.onRequest((req, res) => __awaiter(void 0, void 0, void 0, function* () {
    if (!pubsub) {
        pubsub = new pubsub_1.PubSub();
    }
    yield pubsub
        .topic(process.env.EXT_INSTANCE_ID)
        .publish(Buffer.from(JSON.stringify({})));
    res.status(200).send("Ok");
}));
/**

@google-cloud/pubsub

Cloud Pub/Sub Client Library for Node.js

Apache-2.0
Latest version published 1 month ago

Package Health Score

91 / 100
Full package analysis