@Generated(value="by gapic-generator") public class SubscriptionAdminClient extends Object implements BackgroundResource
To retrieve messages from a subscription, see the Subscriber class.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
PushConfig pushConfig = PushConfig.newBuilder().build();
int ackDeadlineSeconds = 0;
Subscription response = subscriptionAdminClient.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
}
Note: close() needs to be called on the subscriptionAdminClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SubscriptionAdminSettings to create(). For example:
To customize credentials:
SubscriptionAdminSettings subscriptionAdminSettings =
SubscriptionAdminSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SubscriptionAdminClient subscriptionAdminClient =
SubscriptionAdminClient.create(subscriptionAdminSettings);
To customize the endpoint:
SubscriptionAdminSettings subscriptionAdminSettings =
SubscriptionAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
SubscriptionAdminClient subscriptionAdminClient =
SubscriptionAdminClient.create(subscriptionAdminSettings);
Modifier and Type | Class and Description |
---|---|
static class |
SubscriptionAdminClient.ListSnapshotsFixedSizeCollection |
static class |
SubscriptionAdminClient.ListSnapshotsPage |
static class |
SubscriptionAdminClient.ListSnapshotsPagedResponse |
static class |
SubscriptionAdminClient.ListSubscriptionsFixedSizeCollection |
static class |
SubscriptionAdminClient.ListSubscriptionsPage |
static class |
SubscriptionAdminClient.ListSubscriptionsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
SubscriptionAdminClient(SubscriberStub stub) |
protected |
SubscriptionAdminClient(SubscriptionAdminSettings settings)
Constructs an instance of SubscriptionAdminClient, using the given settings.
|
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static SubscriptionAdminClient |
create()
Constructs an instance of SubscriptionAdminClient with default settings.
|
static SubscriptionAdminClient |
create(SubscriberStub stub)
Constructs an instance of SubscriptionAdminClient, using the given stub for making calls.
|
static SubscriptionAdminClient |
create(SubscriptionAdminSettings settings)
Constructs an instance of SubscriptionAdminClient, using the given settings.
|
com.google.pubsub.v1.Snapshot |
createSnapshot(com.google.pubsub.v1.CreateSnapshotRequest request)
Creates a snapshot from the requested subscription.
|
com.google.pubsub.v1.Snapshot |
createSnapshot(com.google.pubsub.v1.ProjectSnapshotName name,
com.google.pubsub.v1.ProjectSubscriptionName subscription)
Creates a snapshot from the requested subscription.
|
com.google.pubsub.v1.Snapshot |
createSnapshot(String name,
String subscription)
Creates a snapshot from the requested subscription.
|
UnaryCallable<com.google.pubsub.v1.CreateSnapshotRequest,com.google.pubsub.v1.Snapshot> |
createSnapshotCallable()
Creates a snapshot from the requested subscription.
|
com.google.pubsub.v1.Subscription |
createSubscription(com.google.pubsub.v1.ProjectSubscriptionName name,
com.google.pubsub.v1.ProjectTopicName topic,
com.google.pubsub.v1.PushConfig pushConfig,
int ackDeadlineSeconds)
Creates a subscription to a given topic.
|
com.google.pubsub.v1.Subscription |
createSubscription(String name,
String topic,
com.google.pubsub.v1.PushConfig pushConfig,
int ackDeadlineSeconds)
Creates a subscription to a given topic.
|
com.google.pubsub.v1.Subscription |
createSubscription(com.google.pubsub.v1.Subscription request)
Creates a subscription to a given topic.
|
UnaryCallable<com.google.pubsub.v1.Subscription,com.google.pubsub.v1.Subscription> |
createSubscriptionCallable()
Creates a subscription to a given topic.
|
void |
deleteSnapshot(com.google.pubsub.v1.DeleteSnapshotRequest request)
Removes an existing snapshot.
|
void |
deleteSnapshot(com.google.pubsub.v1.ProjectSnapshotName snapshot)
Removes an existing snapshot.
|
void |
deleteSnapshot(String snapshot)
Removes an existing snapshot.
|
UnaryCallable<com.google.pubsub.v1.DeleteSnapshotRequest,Empty> |
deleteSnapshotCallable()
Removes an existing snapshot.
|
void |
deleteSubscription(com.google.pubsub.v1.DeleteSubscriptionRequest request)
Deletes an existing subscription.
|
void |
deleteSubscription(com.google.pubsub.v1.ProjectSubscriptionName subscription)
Deletes an existing subscription.
|
void |
deleteSubscription(String subscription)
Deletes an existing subscription.
|
UnaryCallable<com.google.pubsub.v1.DeleteSubscriptionRequest,Empty> |
deleteSubscriptionCallable()
Deletes an existing subscription.
|
com.google.iam.v1.Policy |
getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Gets the access control policy for a resource.
|
com.google.iam.v1.Policy |
getIamPolicy(String resource)
Gets the access control policy for a resource.
|
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Gets the access control policy for a resource.
|
SubscriptionAdminSettings |
getSettings() |
SubscriberStub |
getStub() |
com.google.pubsub.v1.Subscription |
getSubscription(com.google.pubsub.v1.GetSubscriptionRequest request)
Gets the configuration details of a subscription.
|
com.google.pubsub.v1.Subscription |
getSubscription(com.google.pubsub.v1.ProjectSubscriptionName subscription)
Gets the configuration details of a subscription.
|
com.google.pubsub.v1.Subscription |
getSubscription(String subscription)
Gets the configuration details of a subscription.
|
UnaryCallable<com.google.pubsub.v1.GetSubscriptionRequest,com.google.pubsub.v1.Subscription> |
getSubscriptionCallable()
Gets the configuration details of a subscription.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
SubscriptionAdminClient.ListSnapshotsPagedResponse |
listSnapshots(com.google.pubsub.v1.ListSnapshotsRequest request)
Lists the existing snapshots.
|
SubscriptionAdminClient.ListSnapshotsPagedResponse |
listSnapshots(com.google.pubsub.v1.ProjectName project)
Lists the existing snapshots.
|
SubscriptionAdminClient.ListSnapshotsPagedResponse |
listSnapshots(String project)
Lists the existing snapshots.
|
UnaryCallable<com.google.pubsub.v1.ListSnapshotsRequest,com.google.pubsub.v1.ListSnapshotsResponse> |
listSnapshotsCallable()
Lists the existing snapshots.
|
UnaryCallable<com.google.pubsub.v1.ListSnapshotsRequest,SubscriptionAdminClient.ListSnapshotsPagedResponse> |
listSnapshotsPagedCallable()
Lists the existing snapshots.
|
SubscriptionAdminClient.ListSubscriptionsPagedResponse |
listSubscriptions(com.google.pubsub.v1.ListSubscriptionsRequest request)
Lists matching subscriptions.
|
SubscriptionAdminClient.ListSubscriptionsPagedResponse |
listSubscriptions(com.google.pubsub.v1.ProjectName project)
Lists matching subscriptions.
|
SubscriptionAdminClient.ListSubscriptionsPagedResponse |
listSubscriptions(String project)
Lists matching subscriptions.
|
UnaryCallable<com.google.pubsub.v1.ListSubscriptionsRequest,com.google.pubsub.v1.ListSubscriptionsResponse> |
listSubscriptionsCallable()
Lists matching subscriptions.
|
UnaryCallable<com.google.pubsub.v1.ListSubscriptionsRequest,SubscriptionAdminClient.ListSubscriptionsPagedResponse> |
listSubscriptionsPagedCallable()
Lists matching subscriptions.
|
void |
modifyPushConfig(com.google.pubsub.v1.ModifyPushConfigRequest request)
Modifies the `PushConfig` for a specified subscription.
|
void |
modifyPushConfig(com.google.pubsub.v1.ProjectSubscriptionName subscription,
com.google.pubsub.v1.PushConfig pushConfig)
Modifies the `PushConfig` for a specified subscription.
|
void |
modifyPushConfig(String subscription,
com.google.pubsub.v1.PushConfig pushConfig)
Modifies the `PushConfig` for a specified subscription.
|
UnaryCallable<com.google.pubsub.v1.ModifyPushConfigRequest,Empty> |
modifyPushConfigCallable()
Modifies the `PushConfig` for a specified subscription.
|
com.google.pubsub.v1.SeekResponse |
seek(com.google.pubsub.v1.SeekRequest request)
Seeks an existing subscription to a point in time or to a given snapshot, whichever is provided
in the request.
|
UnaryCallable<com.google.pubsub.v1.SeekRequest,com.google.pubsub.v1.SeekResponse> |
seekCallable()
Seeks an existing subscription to a point in time or to a given snapshot, whichever is provided
in the request.
|
com.google.iam.v1.Policy |
setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sets the access control policy on the specified resource.
|
com.google.iam.v1.Policy |
setIamPolicy(String resource,
com.google.iam.v1.Policy policy)
Sets the access control policy on the specified resource.
|
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> |
setIamPolicyCallable()
Sets the access control policy on the specified resource.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(String resource,
List<String> permissions)
Returns permissions that a caller has on the specified resource.
|
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on the specified resource.
|
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that a caller has on the specified resource.
|
com.google.pubsub.v1.Snapshot |
updateSnapshot(com.google.pubsub.v1.UpdateSnapshotRequest request)
Updates an existing snapshot.
|
UnaryCallable<com.google.pubsub.v1.UpdateSnapshotRequest,com.google.pubsub.v1.Snapshot> |
updateSnapshotCallable()
Updates an existing snapshot.
|
com.google.pubsub.v1.Subscription |
updateSubscription(com.google.pubsub.v1.UpdateSubscriptionRequest request)
Updates an existing subscription.
|
UnaryCallable<com.google.pubsub.v1.UpdateSubscriptionRequest,com.google.pubsub.v1.Subscription> |
updateSubscriptionCallable()
Updates an existing subscription.
|
protected SubscriptionAdminClient(SubscriptionAdminSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected SubscriptionAdminClient(SubscriberStub stub)
public static final SubscriptionAdminClient create() throws IOException
IOException
public static final SubscriptionAdminClient create(SubscriptionAdminSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final SubscriptionAdminClient create(SubscriberStub stub)
public final SubscriptionAdminSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public SubscriberStub getStub()
public final com.google.pubsub.v1.Subscription createSubscription(com.google.pubsub.v1.ProjectSubscriptionName name, com.google.pubsub.v1.ProjectTopicName topic, com.google.pubsub.v1.PushConfig pushConfig, int ackDeadlineSeconds)
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](https://cloud.google.com/pubsub/docs/admin#resource_names). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
PushConfig pushConfig = PushConfig.newBuilder().build();
int ackDeadlineSeconds = 0;
Subscription response = subscriptionAdminClient.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
}
name
- 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
- 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
- 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.ackDeadlineSeconds
- The approximate amount of time (on a best-effort basis) Pub/Sub waits
for the subscriber to acknowledge receipt before resending the message. In the interval
after the message is delivered and before it is acknowledged, it is considered to be
<i>outstanding</i>. During that time period, the message will not be
redelivered (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 non-streaming pull or send the `ack_id` in a `StreamingModifyAckDeadlineRequest` if using streaming 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.
ApiException
- if the remote call failspublic final com.google.pubsub.v1.Subscription createSubscription(String name, String topic, com.google.pubsub.v1.PushConfig pushConfig, int ackDeadlineSeconds)
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](https://cloud.google.com/pubsub/docs/admin#resource_names). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
PushConfig pushConfig = PushConfig.newBuilder().build();
int ackDeadlineSeconds = 0;
Subscription response = subscriptionAdminClient.createSubscription(name.toString(), topic.toString(), pushConfig, ackDeadlineSeconds);
}
name
- 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
- 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
- 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.ackDeadlineSeconds
- The approximate amount of time (on a best-effort basis) Pub/Sub waits
for the subscriber to acknowledge receipt before resending the message. In the interval
after the message is delivered and before it is acknowledged, it is considered to be
<i>outstanding</i>. During that time period, the message will not be
redelivered (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 non-streaming pull or send the `ack_id` in a `StreamingModifyAckDeadlineRequest` if using streaming 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.
ApiException
- if the remote call failspublic final com.google.pubsub.v1.Subscription createSubscription(com.google.pubsub.v1.Subscription request)
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](https://cloud.google.com/pubsub/docs/admin#resource_names). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Subscription request = Subscription.newBuilder()
.setName(name.toString())
.setTopic(topic.toString())
.build();
Subscription response = subscriptionAdminClient.createSubscription(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.Subscription,com.google.pubsub.v1.Subscription> createSubscriptionCallable()
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](https://cloud.google.com/pubsub/docs/admin#resource_names). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Subscription request = Subscription.newBuilder()
.setName(name.toString())
.setTopic(topic.toString())
.build();
ApiFuture<Subscription> future = subscriptionAdminClient.createSubscriptionCallable().futureCall(request);
// Do something
Subscription response = future.get();
}
public final com.google.pubsub.v1.Subscription getSubscription(com.google.pubsub.v1.ProjectSubscriptionName subscription)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
Subscription response = subscriptionAdminClient.getSubscription(subscription);
}
subscription
- The name of the subscription to get. Format is
`projects/{project}/subscriptions/{sub}`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Subscription getSubscription(String subscription)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
Subscription response = subscriptionAdminClient.getSubscription(subscription.toString());
}
subscription
- The name of the subscription to get. Format is
`projects/{project}/subscriptions/{sub}`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Subscription getSubscription(com.google.pubsub.v1.GetSubscriptionRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
.setSubscription(subscription.toString())
.build();
Subscription response = subscriptionAdminClient.getSubscription(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.GetSubscriptionRequest,com.google.pubsub.v1.Subscription> getSubscriptionCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
GetSubscriptionRequest request = GetSubscriptionRequest.newBuilder()
.setSubscription(subscription.toString())
.build();
ApiFuture<Subscription> future = subscriptionAdminClient.getSubscriptionCallable().futureCall(request);
// Do something
Subscription response = future.get();
}
public final com.google.pubsub.v1.Subscription updateSubscription(com.google.pubsub.v1.UpdateSubscriptionRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
int ackDeadlineSeconds = 42;
Subscription subscription = Subscription.newBuilder()
.setAckDeadlineSeconds(ackDeadlineSeconds)
.build();
String pathsElement = "ack_deadline_seconds";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder()
.setSubscription(subscription)
.setUpdateMask(updateMask)
.build();
Subscription response = subscriptionAdminClient.updateSubscription(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.UpdateSubscriptionRequest,com.google.pubsub.v1.Subscription> updateSubscriptionCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
int ackDeadlineSeconds = 42;
Subscription subscription = Subscription.newBuilder()
.setAckDeadlineSeconds(ackDeadlineSeconds)
.build();
String pathsElement = "ack_deadline_seconds";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
UpdateSubscriptionRequest request = UpdateSubscriptionRequest.newBuilder()
.setSubscription(subscription)
.setUpdateMask(updateMask)
.build();
ApiFuture<Subscription> future = subscriptionAdminClient.updateSubscriptionCallable().futureCall(request);
// Do something
Subscription response = future.get();
}
public final SubscriptionAdminClient.ListSubscriptionsPagedResponse listSubscriptions(com.google.pubsub.v1.ProjectName project)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Subscription element : subscriptionAdminClient.listSubscriptions(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- The name of the project in which to list subscriptions. Format is
`projects/{project-id}`.ApiException
- if the remote call failspublic final SubscriptionAdminClient.ListSubscriptionsPagedResponse listSubscriptions(String project)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Subscription element : subscriptionAdminClient.listSubscriptions(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- The name of the project in which to list subscriptions. Format is
`projects/{project-id}`.ApiException
- if the remote call failspublic final SubscriptionAdminClient.ListSubscriptionsPagedResponse listSubscriptions(com.google.pubsub.v1.ListSubscriptionsRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
.setProject(project.toString())
.build();
for (Subscription element : subscriptionAdminClient.listSubscriptions(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.ListSubscriptionsRequest,SubscriptionAdminClient.ListSubscriptionsPagedResponse> listSubscriptionsPagedCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
.setProject(project.toString())
.build();
ApiFuture<ListSubscriptionsPagedResponse> future = subscriptionAdminClient.listSubscriptionsPagedCallable().futureCall(request);
// Do something
for (Subscription element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.pubsub.v1.ListSubscriptionsRequest,com.google.pubsub.v1.ListSubscriptionsResponse> listSubscriptionsCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListSubscriptionsRequest request = ListSubscriptionsRequest.newBuilder()
.setProject(project.toString())
.build();
while (true) {
ListSubscriptionsResponse response = subscriptionAdminClient.listSubscriptionsCallable().call(request);
for (Subscription element : response.getSubscriptionsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void deleteSubscription(com.google.pubsub.v1.ProjectSubscriptionName subscription)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
subscriptionAdminClient.deleteSubscription(subscription);
}
subscription
- The subscription to delete. Format is
`projects/{project}/subscriptions/{sub}`.ApiException
- if the remote call failspublic final void deleteSubscription(String subscription)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
subscriptionAdminClient.deleteSubscription(subscription.toString());
}
subscription
- The subscription to delete. Format is
`projects/{project}/subscriptions/{sub}`.ApiException
- if the remote call failspublic final void deleteSubscription(com.google.pubsub.v1.DeleteSubscriptionRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
.setSubscription(subscription.toString())
.build();
subscriptionAdminClient.deleteSubscription(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.DeleteSubscriptionRequest,Empty> deleteSubscriptionCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
DeleteSubscriptionRequest request = DeleteSubscriptionRequest.newBuilder()
.setSubscription(subscription.toString())
.build();
ApiFuture<Void> future = subscriptionAdminClient.deleteSubscriptionCallable().futureCall(request);
// Do something
future.get();
}
public final void modifyPushConfig(com.google.pubsub.v1.ProjectSubscriptionName subscription, com.google.pubsub.v1.PushConfig pushConfig)
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`.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
subscriptionAdminClient.modifyPushConfig(subscription, pushConfig);
}
subscription
- The name of the subscription. Format is
`projects/{project}/subscriptions/{sub}`.pushConfig
- 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` or `StreamingPull` is not called.
ApiException
- if the remote call failspublic final void modifyPushConfig(String subscription, com.google.pubsub.v1.PushConfig pushConfig)
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`.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
subscriptionAdminClient.modifyPushConfig(subscription.toString(), pushConfig);
}
subscription
- The name of the subscription. Format is
`projects/{project}/subscriptions/{sub}`.pushConfig
- 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` or `StreamingPull` is not called.
ApiException
- if the remote call failspublic final void modifyPushConfig(com.google.pubsub.v1.ModifyPushConfigRequest request)
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`.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
.setSubscription(subscription.toString())
.setPushConfig(pushConfig)
.build();
subscriptionAdminClient.modifyPushConfig(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.ModifyPushConfigRequest,Empty> modifyPushConfigCallable()
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`.
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder()
.setSubscription(subscription.toString())
.setPushConfig(pushConfig)
.build();
ApiFuture<Void> future = subscriptionAdminClient.modifyPushConfigCallable().futureCall(request);
// Do something
future.get();
}
public final SubscriptionAdminClient.ListSnapshotsPagedResponse listSnapshots(com.google.pubsub.v1.ProjectName project)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Snapshot element : subscriptionAdminClient.listSnapshots(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- The name of the project in which to list snapshots. Format is
`projects/{project-id}`.ApiException
- if the remote call failspublic final SubscriptionAdminClient.ListSnapshotsPagedResponse listSnapshots(String project)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Snapshot element : subscriptionAdminClient.listSnapshots(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project
- The name of the project in which to list snapshots. Format is
`projects/{project-id}`.ApiException
- if the remote call failspublic final SubscriptionAdminClient.ListSnapshotsPagedResponse listSnapshots(com.google.pubsub.v1.ListSnapshotsRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListSnapshotsRequest request = ListSnapshotsRequest.newBuilder()
.setProject(project.toString())
.build();
for (Snapshot element : subscriptionAdminClient.listSnapshots(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.ListSnapshotsRequest,SubscriptionAdminClient.ListSnapshotsPagedResponse> listSnapshotsPagedCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListSnapshotsRequest request = ListSnapshotsRequest.newBuilder()
.setProject(project.toString())
.build();
ApiFuture<ListSnapshotsPagedResponse> future = subscriptionAdminClient.listSnapshotsPagedCallable().futureCall(request);
// Do something
for (Snapshot element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.pubsub.v1.ListSnapshotsRequest,com.google.pubsub.v1.ListSnapshotsResponse> listSnapshotsCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListSnapshotsRequest request = ListSnapshotsRequest.newBuilder()
.setProject(project.toString())
.build();
while (true) {
ListSnapshotsResponse response = subscriptionAdminClient.listSnapshotsCallable().call(request);
for (Snapshot element : response.getSnapshotsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.pubsub.v1.Snapshot createSnapshot(com.google.pubsub.v1.ProjectSnapshotName name, com.google.pubsub.v1.ProjectSubscriptionName subscription)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName name = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
Snapshot response = subscriptionAdminClient.createSnapshot(name, subscription);
}
name
- 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. See the <a
href="https://cloud.google.com/pubsub/docs/admin#resource_names"> resource name
rules</a>. Format is `projects/{project}/snapshots/{snap}`.subscription
- 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}`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Snapshot createSnapshot(String name, String subscription)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName name = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
Snapshot response = subscriptionAdminClient.createSnapshot(name.toString(), subscription.toString());
}
name
- 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. See the <a
href="https://cloud.google.com/pubsub/docs/admin#resource_names"> resource name
rules</a>. Format is `projects/{project}/snapshots/{snap}`.subscription
- 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}`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Snapshot createSnapshot(com.google.pubsub.v1.CreateSnapshotRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName name = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
CreateSnapshotRequest request = CreateSnapshotRequest.newBuilder()
.setName(name.toString())
.setSubscription(subscription.toString())
.build();
Snapshot response = subscriptionAdminClient.createSnapshot(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.CreateSnapshotRequest,com.google.pubsub.v1.Snapshot> createSnapshotCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName name = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
CreateSnapshotRequest request = CreateSnapshotRequest.newBuilder()
.setName(name.toString())
.setSubscription(subscription.toString())
.build();
ApiFuture<Snapshot> future = subscriptionAdminClient.createSnapshotCallable().futureCall(request);
// Do something
Snapshot response = future.get();
}
public final com.google.pubsub.v1.Snapshot updateSnapshot(com.google.pubsub.v1.UpdateSnapshotRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
long seconds = 123456L;
Timestamp expireTime = Timestamp.newBuilder()
.setSeconds(seconds)
.build();
Snapshot snapshot = Snapshot.newBuilder()
.setExpireTime(expireTime)
.build();
String pathsElement = "expire_time";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder()
.setSnapshot(snapshot)
.setUpdateMask(updateMask)
.build();
Snapshot response = subscriptionAdminClient.updateSnapshot(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.UpdateSnapshotRequest,com.google.pubsub.v1.Snapshot> updateSnapshotCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
long seconds = 123456L;
Timestamp expireTime = Timestamp.newBuilder()
.setSeconds(seconds)
.build();
Snapshot snapshot = Snapshot.newBuilder()
.setExpireTime(expireTime)
.build();
String pathsElement = "expire_time";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
UpdateSnapshotRequest request = UpdateSnapshotRequest.newBuilder()
.setSnapshot(snapshot)
.setUpdateMask(updateMask)
.build();
ApiFuture<Snapshot> future = subscriptionAdminClient.updateSnapshotCallable().futureCall(request);
// Do something
Snapshot response = future.get();
}
public final void deleteSnapshot(com.google.pubsub.v1.ProjectSnapshotName snapshot)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName snapshot = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
subscriptionAdminClient.deleteSnapshot(snapshot);
}
snapshot
- The name of the snapshot to delete. Format is
`projects/{project}/snapshots/{snap}`.ApiException
- if the remote call failspublic final void deleteSnapshot(String snapshot)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName snapshot = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
subscriptionAdminClient.deleteSnapshot(snapshot.toString());
}
snapshot
- The name of the snapshot to delete. Format is
`projects/{project}/snapshots/{snap}`.ApiException
- if the remote call failspublic final void deleteSnapshot(com.google.pubsub.v1.DeleteSnapshotRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName snapshot = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder()
.setSnapshot(snapshot.toString())
.build();
subscriptionAdminClient.deleteSnapshot(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.DeleteSnapshotRequest,Empty> deleteSnapshotCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSnapshotName snapshot = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder()
.setSnapshot(snapshot.toString())
.build();
ApiFuture<Void> future = subscriptionAdminClient.deleteSnapshotCallable().futureCall(request);
// Do something
future.get();
}
public final com.google.pubsub.v1.SeekResponse seek(com.google.pubsub.v1.SeekRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
SeekRequest request = SeekRequest.newBuilder()
.setSubscription(subscription.toString())
.build();
SeekResponse response = subscriptionAdminClient.seek(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.SeekRequest,com.google.pubsub.v1.SeekResponse> seekCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
SeekRequest request = SeekRequest.newBuilder()
.setSubscription(subscription.toString())
.build();
ApiFuture<SeekResponse> future = subscriptionAdminClient.seekCallable().futureCall(request);
// Do something
SeekResponse response = future.get();
}
public final com.google.iam.v1.Policy setIamPolicy(String resource, com.google.iam.v1.Policy policy)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
Policy policy = Policy.newBuilder().build();
Policy response = subscriptionAdminClient.setIamPolicy(formattedResource, policy);
}
resource
- 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
- 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.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.setPolicy(policy)
.build();
Policy response = subscriptionAdminClient.setIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.setPolicy(policy)
.build();
ApiFuture<Policy> future = subscriptionAdminClient.setIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(String resource)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
Policy response = subscriptionAdminClient.getIamPolicy(formattedResource);
}
resource
- 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}`.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.build();
Policy response = subscriptionAdminClient.getIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.build();
ApiFuture<Policy> future = subscriptionAdminClient.getIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response = subscriptionAdminClient.testIamPermissions(formattedResource, permissions);
}
resource
- 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
- 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](https://cloud.google.com/iam/docs/overview#permissions).ApiException
- if the remote call failspublic final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(formattedResource)
.addAllPermissions(permissions)
.build();
TestIamPermissionsResponse response = subscriptionAdminClient.testIamPermissions(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Sample code:
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(formattedResource)
.addAllPermissions(permissions)
.build();
ApiFuture<TestIamPermissionsResponse> future = subscriptionAdminClient.testIamPermissionsCallable().futureCall(request);
// Do something
TestIamPermissionsResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.