v1. SubscriberClient
The service that an application uses to manipulate subscriptions and to consume messages from a subscription via the Pull
method or by establishing a bi-directional stream using the StreamingPull
method.
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
|
Properties
port
The port for this API service.
scopes
The scopes needed to make gRPC calls for every method defined in this service.
servicePath
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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const ackIds = [];
const 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.
ALPHA: This feature is part of an alpha release. This API might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
If the snapshot already
exists, returns ALREADY_EXISTS
. If the requested subscription doesn't exist, returns NOT_FOUND
. If the backlog in the subscription is too old -- and the resulting snapshot would expire in less than 1 hour -- then
FAILED_PRECONDITION
is returned. See also the Snapshot.expire_time
field. 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
|
||||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedName = client.snapshotPath('[PROJECT]', '[SNAPSHOT]');
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const request = {
name: formattedName,
subscription: formattedSubscription,
};
client.createSnapshot(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
createSubscription
createSubscription(request, options, callback) returns Promise
Creates a subscription to a given topic. See the
resource name rules. 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
|
||||||||||||||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedName = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const formattedTopic = client.topicPath('[PROJECT]', '[TOPIC]');
const request = {
name: formattedName,
topic: formattedTopic,
};
client.createSubscription(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
deleteSnapshot
deleteSnapshot(request, options, callback) returns Promise
Removes an existing snapshot.
ALPHA: This feature is part of an alpha release. This API might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy. When the snapshot is deleted,
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
|
||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const 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
|
||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const 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
|
||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedResource = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.getIamPolicy({resource: formattedResource})
.then(responses => {
const 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
|
||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.getSubscription({subscription: formattedSubscription})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
listSnapshots
listSnapshots(request, options, callback) returns Promise
Lists the existing snapshots.
ALPHA: This feature is part of an alpha release. This API might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
// Iterate over all elements.
const formattedProject = client.projectPath('[PROJECT]');
client.listSnapshots({project: formattedProject})
.then(responses => {
const 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.
const formattedProject = client.projectPath('[PROJECT]');
const options = {autoPaginate: false};
const callback = responses => {
// The actual resources in a response.
const resources = responses[0];
// The next request if the response shows that there are more responses.
const nextRequest = responses[1];
// The actual response object, if necessary.
// const 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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const 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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
// Iterate over all elements.
const formattedProject = client.projectPath('[PROJECT]');
client.listSubscriptions({project: formattedProject})
.then(responses => {
const 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.
const formattedProject = client.projectPath('[PROJECT]');
const options = {autoPaginate: false};
const callback = responses => {
// The actual resources in a response.
const resources = responses[0];
// The next request if the response shows that there are more responses.
const nextRequest = responses[1];
// The actual response object, if necessary.
// const 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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const 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
|
||||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const ackIds = [];
const ackDeadlineSeconds = 0;
const 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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const pushConfig = {};
const 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. 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
|
||||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const maxMessages = 0;
const request = {
subscription: formattedSubscription,
maxMessages: maxMessages,
};
client.pull(request)
.then(responses => {
const 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.
ALPHA: This feature is part of an alpha release. This API might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
client.seek({subscription: formattedSubscription})
.then(responses => {
const 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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedResource = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const policy = {};
const request = {
resource: formattedResource,
policy: policy,
};
client.setIamPolicy(request)
.then(responses => {
const 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
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 UNAVAILABLE
to reassign server-side resources, in which case, the client should re-establish the stream. 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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const stream = client.streamingPull().on('data', response => {
// doThingsWith(response)
});
const formattedSubscription = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const streamAckDeadlineSeconds = 0;
const request = {
subscription: formattedSubscription,
streamAckDeadlineSeconds: streamAckDeadlineSeconds,
};
// 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
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const formattedResource = client.subscriptionPath('[PROJECT]', '[SUBSCRIPTION]');
const permissions = [];
const request = {
resource: formattedResource,
permissions: permissions,
};
client.testIamPermissions(request)
.then(responses => {
const 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.
ALPHA: This feature is part of an alpha release. This API might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy. Note that certain properties
of a snapshot are not modifiable.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const seconds = 123456;
const expireTime = {
seconds: seconds,
};
const snapshot = {
expireTime: expireTime,
};
const pathsElement = 'expire_time';
const paths = [pathsElement];
const updateMask = {
paths: paths,
};
const request = {
snapshot: snapshot,
updateMask: updateMask,
};
client.updateSnapshot(request)
.then(responses => {
const 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.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
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');
const client = new pubsub.v1.SubscriberClient({
// optional auth parameters.
});
const ackDeadlineSeconds = 42;
const subscription = {
ackDeadlineSeconds: ackDeadlineSeconds,
};
const pathsElement = 'ack_deadline_seconds';
const paths = [pathsElement];
const updateMask = {
paths: paths,
};
const request = {
subscription: subscription,
updateMask: updateMask,
};
client.updateSubscription(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});