How to use the @google-cloud/pubsub.v1.PublisherClient 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 googleapis / nodejs-pubsub / samples / topics.js View on Github external
async function publishWithRetrySettings(projectId, topicName, data) {
  // [START pubsub_publisher_retry_settings]
  // Imports the Google Cloud client library
  const {v1} = require('@google-cloud/pubsub');

  // Creates a publisher client
  const client = new v1.PublisherClient({
    // optional auth parameters
  });

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

  const formattedTopic = client.topicPath(projectId, topicName);
  // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
  const dataBuffer = Buffer.from(data);
  const messagesElement = {
    data: dataBuffer,
  };

@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