Constructor

SubscriberClient

new SubscriberClient(options)

Construct an instance of SubscriberClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Values in options have the following properties:

Parameter

credentials

Optional

object

Credentials object.

credentials.client_email

Optional

string

credentials.private_key

Optional

string

email

Optional

string

Account email address. Required when usaing a .pem or .p12 keyFilename.

keyFilename

Optional

string

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option above is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port

Optional

number

The port on which to connect to the remote host.

projectId

Optional

string

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise

Optional

function()

Custom promise module to use instead of native Promises.

servicePath

Optional

string

The domain name of the API remote host.

Properties

port

static

The port for this API service.

scopes

static

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static

The DNS address for this API service.

Methods

acknowledge

acknowledge(request, options, callback) returns Promise

Acknowledges the messages associated with the ack_ids in the AcknowledgeRequest. The Pub/Sub system can remove the relevant messages from the subscription.

Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later. Acknowledging a message more than once will not result in an error.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The subscription whose message is being acknowledged. Format is projects/{project}/subscriptions/{sub}.

ackIds

Array of 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.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var ackIds = [];
var request = {
  subscription: formattedSubscription,
  ackIds: ackIds,
};
client.acknowledge(request).catch(err => {
  console.error(err);
});

createSnapshot

createSnapshot(request, options, callback) returns Promise

Creates a snapshot from the requested subscription. If the snapshot already exists, returns ALREADY_EXISTS. If the requested subscription doesn't exist, returns NOT_FOUND.

If the name is not provided in the request, the server will assign a random name for this snapshot on the same project as the subscription, conforming to the resource name format. The generated name is populated in the returned Snapshot object. Note that for REST API requests, you must specify a name in the request.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

Optional user-provided name for this snapshot. If the name is not provided in the request, the server will assign a random name for this snapshot on the same project as the subscription. Note that for REST API requests, you must specify a name. Format is projects/{project}/snapshots/{snap}.

subscription

string

The subscription whose backlog the snapshot retains. Specifically, the created snapshot is guaranteed to retain: (a) The existing backlog on the subscription. More precisely, this is defined as the messages in the subscription's backlog that are unacknowledged upon the successful completion of the CreateSnapshot request; as well as: (b) Any messages published to the subscription's topic following the successful completion of the CreateSnapshot request. Format is projects/{project}/subscriptions/{sub}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Snapshot.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Snapshot. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedName = client.snapshotPath('[PROJECT]', '[SNAPSHOT]');
var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var request = {
  name: formattedName,
  subscription: formattedSubscription,
};
client.createSnapshot(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

createSubscription

createSubscription(request, options, callback) returns Promise

Creates a subscription to a given topic. If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.

If the name is not provided in the request, the server will assign a random name for this subscription on the same project as the topic, conforming to the resource name format. The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the subscription. It must have the format "projects/{project}/subscriptions/{subscription}". {subscription} must start with a letter, and contain only letters ([A-Za-z]), numbers ( [0-9]), dashes (-), underscores (_), periods (.), tildes (~), plus (+) or percent signs (%). It must be between 3 and 255 characters in length, and it must not start with "goog".

topic

string

The name of the topic from which this subscription is receiving messages. Format is projects/{project}/topics/{topic}. The value of this field will be deleted-topic if the topic has been deleted.

pushConfig

Optional

Object

If push delivery is used with this subscription, this field is used to configure it. An empty pushConfig signifies that the subscriber will pull and ack messages using API methods.

This object should have the same structure as PushConfig

ackDeadlineSeconds

Optional

number

This value is the maximum time after a subscriber receives a message before the subscriber should acknowledge the message. After message delivery but before the ack deadline expires and before the message is acknowledged, it is an outstanding message and will not be delivered again during that time (on a best-effort basis).

For pull subscriptions, this value is used as the initial value for the ack deadline. To override this value for a given message, call ModifyAckDeadline with the corresponding ack_id if using pull. The minimum custom deadline you can specify is 10 seconds. The maximum custom deadline you can specify is 600 seconds (10 minutes). If this parameter is 0, a default value of 10 seconds is used.

For push delivery, this value is also used to set the request timeout for the call to the push endpoint.

If the subscriber never acknowledges the message, the Pub/Sub system will eventually redeliver the message.

retainAckedMessages

Optional

boolean

Indicates whether to retain acknowledged messages. If true, then messages are not expunged from the subscription's backlog, even if they are acknowledged, until they fall out of the message_retention_duration window.

messageRetentionDuration

Optional

Object

How long to retain unacknowledged messages in the subscription's backlog, from the moment a message is published. If retain_acked_messages is true, then this also configures the retention of acknowledged messages, and thus configures how far back in time a Seek can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 minutes.

This object should have the same structure as Duration

labels

Optional

Object with string properties

User labels.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Subscription.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Subscription. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedName = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var formattedTopic = client.topicPath('[PROJECT]', '[TOPIC]');
var request = {
  name: formattedName,
  topic: formattedTopic,
};
client.createSubscription(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

deleteSnapshot

deleteSnapshot(request, options, callback) returns Promise

Removes an existing snapshot. All messages retained in the snapshot are immediately dropped. After a snapshot is deleted, a new one may be created with the same name, but the new one has no association with the old snapshot or its subscription, unless the same subscription is specified.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

snapshot

string

The name of the snapshot to delete. Format is projects/{project}/snapshots/{snap}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSnapshot = client.snapshotPath('[PROJECT]', '[SNAPSHOT]');
client.deleteSnapshot({snapshot: formattedSnapshot}).catch(err => {
  console.error(err);
});

deleteSubscription

deleteSubscription(request, options, callback) returns Promise

Deletes an existing subscription. All messages retained in the subscription are immediately dropped. Calls to Pull after deletion will return NOT_FOUND. After a subscription is deleted, a new one may be created with the same name, but the new one has no association with the old subscription or its topic unless the same topic is specified.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The subscription to delete. Format is projects/{project}/subscriptions/{sub}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.deleteSubscription({subscription: formattedSubscription}).catch(err => {
  console.error(err);
});

getIamPolicy

getIamPolicy(request, options, callback) returns Promise

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

resource

string

REQUIRED: The resource for which the policy is being requested. resource is usually specified as a path. For example, a Project resource is specified as projects/{project}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Policy.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Policy. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedResource = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.getIamPolicy({resource: formattedResource})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.

getSubscription

getSubscription(request, options, callback) returns Promise

Gets the configuration details of a subscription.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The name of the subscription to get. Format is projects/{project}/subscriptions/{sub}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Subscription.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Subscription. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.getSubscription({subscription: formattedSubscription})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

listSnapshots

listSnapshots(request, options, callback) returns Promise

Lists the existing snapshots.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

project

string

The name of the cloud project that snapshots belong to. Format is projects/{project}.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is Array of Snapshot.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListSnapshotsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of Snapshot.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Snapshot in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListSnapshotsResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

// Iterate over all elements.
var formattedProject = client.projectPath('[PROJECT]');

client.listSnapshots({project: formattedProject})
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
var formattedProject = client.projectPath('[PROJECT]');


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listSnapshots(nextRequest, options).then(callback);
  }
}
client.listSnapshots({project: formattedProject}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listSnapshotsStream

listSnapshotsStream(request, options) returns Stream

Equivalent to listSnapshots, but returns a NodeJS Stream object.

This fetches the paged responses for listSnapshots continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

project

string

The name of the cloud project that snapshots belong to. Format is projects/{project}.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing Snapshot on 'data' event.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedProject = client.projectPath('[PROJECT]');
client.listSnapshotsStream({project: formattedProject})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listSubscriptions

listSubscriptions(request, options, callback) returns Promise

Lists matching subscriptions.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

project

string

The name of the cloud project that subscriptions belong to. Format is projects/{project}.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is Array of Subscription.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListSubscriptionsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of Subscription.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Subscription in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListSubscriptionsResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

// Iterate over all elements.
var formattedProject = client.projectPath('[PROJECT]');

client.listSubscriptions({project: formattedProject})
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
var formattedProject = client.projectPath('[PROJECT]');


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listSubscriptions(nextRequest, options).then(callback);
  }
}
client.listSubscriptions({project: formattedProject}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listSubscriptionsStream

listSubscriptionsStream(request, options) returns Stream

Equivalent to listSubscriptions, but returns a NodeJS Stream object.

This fetches the paged responses for listSubscriptions continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

project

string

The name of the cloud project that subscriptions belong to. Format is projects/{project}.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing Subscription on 'data' event.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedProject = client.projectPath('[PROJECT]');
client.listSubscriptionsStream({project: formattedProject})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

matchProjectFromProjectName

matchProjectFromProjectName(projectName) returns String

Parse the projectName from a project resource.

Parameter

projectName

String

A fully-qualified path representing a project resources.

Returns

String 

  • A string representing the project.

matchProjectFromSnapshotName

matchProjectFromSnapshotName(snapshotName) returns String

Parse the snapshotName from a snapshot resource.

Parameter

snapshotName

String

A fully-qualified path representing a snapshot resources.

Returns

String 

  • A string representing the project.

matchProjectFromSubscriptionName

matchProjectFromSubscriptionName(subscriptionName) returns String

Parse the subscriptionName from a subscription resource.

Parameter

subscriptionName

String

A fully-qualified path representing a subscription resources.

Returns

String 

  • A string representing the project.

matchProjectFromTopicName

matchProjectFromTopicName(topicName) returns String

Parse the topicName from a topic resource.

Parameter

topicName

String

A fully-qualified path representing a topic resources.

Returns

String 

  • A string representing the project.

matchSnapshotFromSnapshotName

matchSnapshotFromSnapshotName(snapshotName) returns String

Parse the snapshotName from a snapshot resource.

Parameter

snapshotName

String

A fully-qualified path representing a snapshot resources.

Returns

String 

  • A string representing the snapshot.

matchSubscriptionFromSubscriptionName

matchSubscriptionFromSubscriptionName(subscriptionName) returns String

Parse the subscriptionName from a subscription resource.

Parameter

subscriptionName

String

A fully-qualified path representing a subscription resources.

Returns

String 

  • A string representing the subscription.

matchTopicFromTopicName

matchTopicFromTopicName(topicName) returns String

Parse the topicName from a topic resource.

Parameter

topicName

String

A fully-qualified path representing a topic resources.

Returns

String 

  • A string representing the topic.

modifyAckDeadline

modifyAckDeadline(request, options, callback) returns Promise

Modifies the ack deadline for a specific message. This method is useful to indicate that more time is needed to process a message by the subscriber, or to make the message available for redelivery if the processing was interrupted. Note that this does not modify the subscription-level ackDeadlineSeconds used for subsequent messages.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The name of the subscription. Format is projects/{project}/subscriptions/{sub}.

ackIds

Array of string

List of acknowledgment IDs.

ackDeadlineSeconds

number

The new ack deadline with respect to the time this request was sent to the Pub/Sub system. For example, if the value is 10, the new ack deadline will expire 10 seconds after the ModifyAckDeadline call was made. Specifying zero may immediately make the message available for another pull request. The minimum deadline you can specify is 0 seconds. The maximum deadline you can specify is 600 seconds (10 minutes).

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var ackIds = [];
var ackDeadlineSeconds = 0;
var request = {
  subscription: formattedSubscription,
  ackIds: ackIds,
  ackDeadlineSeconds: ackDeadlineSeconds,
};
client.modifyAckDeadline(request).catch(err => {
  console.error(err);
});

modifyPushConfig

modifyPushConfig(request, options, callback) returns Promise

Modifies the PushConfig for a specified subscription.

This may be used to change a push subscription to a pull one (signified by an empty PushConfig) or vice versa, or change the endpoint URL and other attributes of a push subscription. Messages will accumulate for delivery continuously through the call regardless of changes to the PushConfig.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The name of the subscription. Format is projects/{project}/subscriptions/{sub}.

pushConfig

Object

The push configuration for future deliveries.

An empty pushConfig indicates that the Pub/Sub system should stop pushing messages from the given subscription and allow messages to be pulled and acknowledged - effectively pausing the subscription if Pull is not called.

This object should have the same structure as PushConfig

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var pushConfig = {};
var request = {
  subscription: formattedSubscription,
  pushConfig: pushConfig,
};
client.modifyPushConfig(request).catch(err => {
  console.error(err);
});

projectPath

projectPath(project) returns String

Return a fully-qualified project resource name string.

Parameter

project

String

Returns

String 

pull

pull(request, options, callback) returns Promise

Pulls messages from the server. Returns an empty list if there are no messages available in the backlog. The server may return UNAVAILABLE if there are too many concurrent pull requests pending for the given subscription.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The subscription from which messages should be pulled. Format is projects/{project}/subscriptions/{sub}.

maxMessages

number

The maximum number of messages returned for this request. The Pub/Sub system may return fewer than the number specified.

returnImmediately

Optional

boolean

If this field set to true, the system will respond immediately even if it there are no messages available to return in the Pull response. Otherwise, the system may wait (for a bounded amount of time) until at least one message is available, rather than returning no messages. The client may cancel the request if it does not wish to wait any longer for the response.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing PullResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing PullResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var maxMessages = 0;
var request = {
  subscription: formattedSubscription,
  maxMessages: maxMessages,
};
client.pull(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

seek

seek(request, options, callback) returns Promise

Seeks an existing subscription to a point in time or to a given snapshot, whichever is provided in the request.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

string

The subscription to affect.

time

Optional

Object

The time to seek to. Messages retained in the subscription that were published before this time are marked as acknowledged, and messages retained in the subscription that were published after this time are marked as unacknowledged. Note that this operation affects only those messages retained in the subscription (configured by the combination of message_retention_duration and retain_acked_messages). For example, if time corresponds to a point before the message retention window (or to a point before the system's notion of the subscription creation time), only retained messages will be marked as unacknowledged, and already-expunged messages will not be restored.

This object should have the same structure as Timestamp

snapshot

Optional

string

The snapshot to seek to. The snapshot's topic must be the same as that of the provided subscription. Format is projects/{project}/snapshots/{snap}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing SeekResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing SeekResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.seek({subscription: formattedSubscription})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

setIamPolicy

setIamPolicy(request, options, callback) returns Promise

Sets the access control policy on the specified resource. Replaces any existing policy.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

resource

string

REQUIRED: The resource for which the policy is being specified. resource is usually specified as a path. For example, a Project resource is specified as projects/{project}.

policy

Object

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

This object should have the same structure as Policy

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Policy.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Policy. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedResource = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var policy = {};
var request = {
  resource: formattedResource,
  policy: policy,
};
client.setIamPolicy(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

snapshotPath

snapshotPath(project, snapshot) returns String

Return a fully-qualified snapshot resource name string.

Parameter

project

String

snapshot

String

Returns

String 

streamingPull

streamingPull(options) returns Stream

(EXPERIMENTAL) StreamingPull is an experimental feature. This RPC will respond with UNIMPLEMENTED errors unless you have been invited to test this feature. Contact cloud-pubsub@google.com with any questions.

Establishes a stream with the server, which sends messages down to the client. The client streams acknowledgements and ack deadline modifications back to the server. The server will close the stream and return the status on any error. The server may close the stream with status OK to reassign server-side resources, in which case, the client should re-establish the stream. UNAVAILABLE may also be returned in the case of a transient error (e.g., a server restart). These should also be retried by the client. Flow control can be achieved by configuring the underlying RPC channel.

Parameter

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Returns

Stream 

An object stream which is both readable and writable. It accepts objects representing StreamingPullRequest for write() method, and will emit objects representing StreamingPullResponse on 'data' event asynchronously.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var stream = client.streamingPull().on('data', response => {
  // doThingsWith(response)
});
var formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var streamAckDeadlineSeconds = 0;
var request = {
  subscription: formattedSubscription,
  streamAckDeadlineSeconds: streamAckDeadlineSeconds,
};
var request = {
  root: request,
};
// Write request objects.
stream.write(request);

subscriptionPath

subscriptionPath(project, subscription) returns String

Return a fully-qualified subscription resource name string.

Parameter

project

String

subscription

String

Returns

String 

testIamPermissions

testIamPermissions(request, options, callback) returns Promise

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

resource

string

REQUIRED: The resource for which the policy detail is being requested. resource is usually specified as a path. For example, a Project resource is specified as projects/{project}.

permissions

Array of string

The set of permissions to check for the resource. Permissions with wildcards (such as '' or 'storage.') are not allowed. For more information see IAM Overview.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing TestIamPermissionsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing TestIamPermissionsResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var formattedResource = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
var permissions = [];
var request = {
  resource: formattedResource,
  permissions: permissions,
};
client.testIamPermissions(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

topicPath

topicPath(project, topic) returns String

Return a fully-qualified topic resource name string.

Parameter

project

String

topic

String

Returns

String 

updateSnapshot

updateSnapshot(request, options, callback) returns Promise

Updates an existing snapshot. Note that certain properties of a snapshot are not modifiable. NOTE: The style guide requires body: "snapshot" instead of body: "*". Keeping the latter for internal consistency in V1, however it should be corrected in V2. See https://cloud.google.com/apis/design/standard_methods#update for details.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

snapshot

Object

The updated snpashot object.

This object should have the same structure as Snapshot

updateMask

Object

Indicates which fields in the provided snapshot to update. Must be specified and non-empty.

This object should have the same structure as FieldMask

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Snapshot.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Snapshot. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var seconds = 123456;
var expireTime = {
  seconds: seconds,
};
var snapshot = {
  expireTime: expireTime,
};
var pathsElement = 'expire_time';
var paths = [pathsElement];
var updateMask = {
  paths: paths,
};
var request = {
  snapshot: snapshot,
  updateMask: updateMask,
};
client.updateSnapshot(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

updateSubscription

updateSubscription(request, options, callback) returns Promise

Updates an existing subscription. Note that certain properties of a subscription, such as its topic, are not modifiable. NOTE: The style guide requires body: "subscription" instead of body: "*". Keeping the latter for internal consistency in V1, however it should be corrected in V2. See https://cloud.google.com/apis/design/standard_methods#update for details.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

subscription

Object

The updated subscription object.

This object should have the same structure as Subscription

updateMask

Object

Indicates which fields in the provided subscription to update. Must be specified and non-empty.

This object should have the same structure as FieldMask

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Subscription.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Subscription. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const pubsub = require('@google-cloud/pubsub');

var client = new pubsub.v1.SubscriberClient({
  // optional auth parameters.
});

var ackDeadlineSeconds = 42;
var subscription = {
  ackDeadlineSeconds: ackDeadlineSeconds,
};
var pathsElement = 'ack_deadline_seconds';
var paths = [pathsElement];
var updateMask = {
  paths: paths,
};
var request = {
  subscription: subscription,
  updateMask: updateMask,
};
client.updateSubscription(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });