Constructor

SubscriberClient

new SubscriberClient(options)

Construct an instance of SubscriberClient.

Parameter

options

Optional

object

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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);
  });