@Generated(value="by gapic-generator-java") public class TopicAdminClient extends Object implements com.google.api.gax.core.BackgroundResource
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:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
Note: close() needs to be called on the TopicAdminClient 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 TopicAdminSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
TopicAdminSettings topicAdminSettings =
TopicAdminSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
TopicAdminSettings topicAdminSettings =
TopicAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
TopicAdminSettings topicAdminSettings = TopicAdminSettings.newHttpJsonBuilder().build();
TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier and Type | Class and Description |
---|---|
static class |
TopicAdminClient.ListTopicsFixedSizeCollection |
static class |
TopicAdminClient.ListTopicSnapshotsFixedSizeCollection |
static class |
TopicAdminClient.ListTopicSnapshotsPage |
static class |
TopicAdminClient.ListTopicSnapshotsPagedResponse |
static class |
TopicAdminClient.ListTopicsPage |
static class |
TopicAdminClient.ListTopicsPagedResponse |
static class |
TopicAdminClient.ListTopicSubscriptionsFixedSizeCollection |
static class |
TopicAdminClient.ListTopicSubscriptionsPage |
static class |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
TopicAdminClient(PublisherStub stub) |
protected |
TopicAdminClient(TopicAdminSettings settings)
Constructs an instance of TopicAdminClient, using the given settings.
|
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static TopicAdminClient |
create()
Constructs an instance of TopicAdminClient with default settings.
|
static TopicAdminClient |
create(PublisherStub stub)
Constructs an instance of TopicAdminClient, using the given stub for making calls.
|
static TopicAdminClient |
create(TopicAdminSettings settings)
Constructs an instance of TopicAdminClient, using the given settings.
|
Topic |
createTopic(ProjectTopicName name)
Deprecated.
Use
createTopic(TopicName) instead. |
Topic |
createTopic(String name)
Creates the given topic with the given name.
|
Topic |
createTopic(Topic request)
Creates the given topic with the given name.
|
Topic |
createTopic(TopicName name)
Creates the given topic with the given name.
|
com.google.api.gax.rpc.UnaryCallable<Topic,Topic> |
createTopicCallable()
Creates the given topic with the given name.
|
void |
deleteTopic(DeleteTopicRequest request)
Deletes the topic with the given name.
|
void |
deleteTopic(ProjectTopicName topic)
Deprecated.
Use
deleteTopic(TopicName) instead. |
void |
deleteTopic(String topic)
Deletes the topic with the given name.
|
void |
deleteTopic(TopicName topic)
Deletes the topic with the given name.
|
com.google.api.gax.rpc.UnaryCallable<DeleteTopicRequest,com.google.protobuf.Empty> |
deleteTopicCallable()
Deletes the topic with the given name.
|
DetachSubscriptionResponse |
detachSubscription(DetachSubscriptionRequest request)
Detaches a subscription from this topic.
|
com.google.api.gax.rpc.UnaryCallable<DetachSubscriptionRequest,DetachSubscriptionResponse> |
detachSubscriptionCallable()
Detaches a subscription from this topic.
|
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)
Deprecated.
Use
getIamPolicy(GetIamPolicyRequest) instead. |
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Gets the access control policy for a resource.
|
TopicAdminSettings |
getSettings() |
PublisherStub |
getStub() |
Topic |
getTopic(GetTopicRequest request)
Gets the configuration of a topic.
|
Topic |
getTopic(ProjectTopicName topic)
Deprecated.
Use
getTopic(TopicName) instead. |
Topic |
getTopic(String topic)
Gets the configuration of a topic.
|
Topic |
getTopic(TopicName topic)
Gets the configuration of a topic.
|
com.google.api.gax.rpc.UnaryCallable<GetTopicRequest,Topic> |
getTopicCallable()
Gets the configuration of a topic.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
TopicAdminClient.ListTopicsPagedResponse |
listTopics(ListTopicsRequest request)
Lists matching topics.
|
TopicAdminClient.ListTopicsPagedResponse |
listTopics(ProjectName project)
Lists matching topics.
|
TopicAdminClient.ListTopicsPagedResponse |
listTopics(String project)
Lists matching topics.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,ListTopicsResponse> |
listTopicsCallable()
Lists matching topics.
|
TopicAdminClient.ListTopicSnapshotsPagedResponse |
listTopicSnapshots(ListTopicSnapshotsRequest request)
Lists the names of the snapshots on this topic.
|
TopicAdminClient.ListTopicSnapshotsPagedResponse |
listTopicSnapshots(String topic)
Lists the names of the snapshots on this topic.
|
TopicAdminClient.ListTopicSnapshotsPagedResponse |
listTopicSnapshots(TopicName topic)
Lists the names of the snapshots on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicSnapshotsRequest,ListTopicSnapshotsResponse> |
listTopicSnapshotsCallable()
Lists the names of the snapshots on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicSnapshotsRequest,TopicAdminClient.ListTopicSnapshotsPagedResponse> |
listTopicSnapshotsPagedCallable()
Lists the names of the snapshots on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> |
listTopicsPagedCallable()
Lists matching topics.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(ListTopicSubscriptionsRequest request)
Lists the names of the attached subscriptions on this topic.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(ProjectTopicName topic)
Deprecated.
Use
listTopicSubscriptions(TopicName) instead. |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(String topic)
Lists the names of the attached subscriptions on this topic.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(TopicName topic)
Lists the names of the attached subscriptions on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse> |
listTopicSubscriptionsCallable()
Lists the names of the attached subscriptions on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,TopicAdminClient.ListTopicSubscriptionsPagedResponse> |
listTopicSubscriptionsPagedCallable()
Lists the names of the attached subscriptions on this topic.
|
PublishResponse |
publish(PublishRequest request)
Adds one or more messages to the topic.
|
PublishResponse |
publish(String topic,
List<PubsubMessage> messages)
Adds one or more messages to the topic.
|
PublishResponse |
publish(TopicName topic,
List<PubsubMessage> messages)
Adds one or more messages to the topic.
|
com.google.api.gax.rpc.UnaryCallable<PublishRequest,PublishResponse> |
publishCallable()
Adds one or more messages to the topic.
|
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)
Deprecated.
Use
setIamPolicy(SetIamPolicyRequest) instead. |
com.google.api.gax.rpc.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)
Deprecated.
Use
testIamPermissions(TestIamPermissionsRequest) instead. |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on the specified resource.
|
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that a caller has on the specified resource.
|
Topic |
updateTopic(Topic topic,
com.google.protobuf.FieldMask updateMask)
Updates an existing topic.
|
Topic |
updateTopic(UpdateTopicRequest request)
Updates an existing topic.
|
com.google.api.gax.rpc.UnaryCallable<UpdateTopicRequest,Topic> |
updateTopicCallable()
Updates an existing topic.
|
protected TopicAdminClient(TopicAdminSettings settings) throws IOException
IOException
protected TopicAdminClient(PublisherStub stub)
public static final TopicAdminClient create() throws IOException
IOException
public static final TopicAdminClient create(TopicAdminSettings settings) throws IOException
IOException
public static final TopicAdminClient create(PublisherStub stub)
public final TopicAdminSettings getSettings()
public PublisherStub getStub()
public final Topic createTopic(TopicName name)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
name
- Required. The name of the topic. It must have the format
`"projects/{project}/topics/{topic}"`. `{topic}` 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"`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Topic createTopic(String name)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
Topic response = topicAdminClient.createTopic(name);
}
name
- Required. The name of the topic. It must have the format
`"projects/{project}/topics/{topic}"`. `{topic}` 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"`.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final Topic createTopic(ProjectTopicName name)
createTopic(TopicName)
instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
name
- Required. The name of the topic. It must have the format
`"projects/{project}/topics/{topic}"`. `{topic}` 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"`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Topic createTopic(Topic request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic request =
Topic.newBuilder()
.setName(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<String, String>())
.setMessageStoragePolicy(MessageStoragePolicy.newBuilder().build())
.setKmsKeyName("kmsKeyName412586233")
.setSchemaSettings(SchemaSettings.newBuilder().build())
.setSatisfiesPzs(true)
.setMessageRetentionDuration(Duration.newBuilder().build())
.build();
Topic response = topicAdminClient.createTopic(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<Topic,Topic> createTopicCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic request =
Topic.newBuilder()
.setName(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.putAllLabels(new HashMap<String, String>())
.setMessageStoragePolicy(MessageStoragePolicy.newBuilder().build())
.setKmsKeyName("kmsKeyName412586233")
.setSchemaSettings(SchemaSettings.newBuilder().build())
.setSatisfiesPzs(true)
.setMessageRetentionDuration(Duration.newBuilder().build())
.build();
ApiFuture<Topic> future = topicAdminClient.createTopicCallable().futureCall(request);
// Do something.
Topic response = future.get();
}
public final Topic updateTopic(Topic topic, com.google.protobuf.FieldMask updateMask)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic topic = Topic.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Topic response = topicAdminClient.updateTopic(topic, updateMask);
}
topic
- Required. The updated topic object.updateMask
- Required. Indicates which fields in the provided topic to update. Must be
specified and non-empty. Note that if `update_mask` contains "message_storage_policy" but
the `message_storage_policy` is not set in the `topic` provided above, then the updated
value is determined by the policy configured at the project or organization level.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Topic updateTopic(UpdateTopicRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
UpdateTopicRequest request =
UpdateTopicRequest.newBuilder()
.setTopic(Topic.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Topic response = topicAdminClient.updateTopic(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<UpdateTopicRequest,Topic> updateTopicCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
UpdateTopicRequest request =
UpdateTopicRequest.newBuilder()
.setTopic(Topic.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Topic> future = topicAdminClient.updateTopicCallable().futureCall(request);
// Do something.
Topic response = future.get();
}
public final PublishResponse publish(TopicName topic, List<PubsubMessage> messages)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
List<PubsubMessage> messages = new ArrayList<>();
PublishResponse response = topicAdminClient.publish(topic, messages);
}
topic
- Required. The messages in the request will be published on this topic. Format is
`projects/{project}/topics/{topic}`.messages
- Required. The messages to publish.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final PublishResponse publish(String topic, List<PubsubMessage> messages)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
List<PubsubMessage> messages = new ArrayList<>();
PublishResponse response = topicAdminClient.publish(topic, messages);
}
topic
- Required. The messages in the request will be published on this topic. Format is
`projects/{project}/topics/{topic}`.messages
- Required. The messages to publish.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final PublishResponse publish(PublishRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
PublishRequest request =
PublishRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.addAllMessages(new ArrayList<PubsubMessage>())
.build();
PublishResponse response = topicAdminClient.publish(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<PublishRequest,PublishResponse> publishCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
PublishRequest request =
PublishRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.addAllMessages(new ArrayList<PubsubMessage>())
.build();
ApiFuture<PublishResponse> future = topicAdminClient.publishCallable().futureCall(request);
// Do something.
PublishResponse response = future.get();
}
public final Topic getTopic(TopicName topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
topic
- Required. The name of the topic to get. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Topic getTopic(String topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
Topic response = topicAdminClient.getTopic(topic);
}
topic
- Required. The name of the topic to get. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final Topic getTopic(ProjectTopicName topic)
getTopic(TopicName)
instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
topic
- Required. The name of the topic to get. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Topic getTopic(GetTopicRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
GetTopicRequest request =
GetTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
Topic response = topicAdminClient.getTopic(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetTopicRequest,Topic> getTopicCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
GetTopicRequest request =
GetTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
ApiFuture<Topic> future = topicAdminClient.getTopicCallable().futureCall(request);
// Do something.
Topic response = future.get();
}
public final TopicAdminClient.ListTopicsPagedResponse listTopics(ProjectName project)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Topic element : topicAdminClient.listTopics(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Required. The name of the project in which to list topics. Format is
`projects/{project-id}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicsPagedResponse listTopics(String project)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String project = ProjectName.of("[PROJECT]").toString();
for (Topic element : topicAdminClient.listTopics(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- Required. The name of the project in which to list topics. Format is
`projects/{project-id}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicsPagedResponse listTopics(ListTopicsRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest request =
ListTopicsRequest.newBuilder()
.setProject(ProjectName.of("[PROJECT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Topic element : topicAdminClient.listTopics(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> listTopicsPagedCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest request =
ListTopicsRequest.newBuilder()
.setProject(ProjectName.of("[PROJECT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Topic> future = topicAdminClient.listTopicsPagedCallable().futureCall(request);
// Do something.
for (Topic element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,ListTopicsResponse> listTopicsCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest request =
ListTopicsRequest.newBuilder()
.setProject(ProjectName.of("[PROJECT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListTopicsResponse response = topicAdminClient.listTopicsCallable().call(request);
for (Topic element : response.getTopicsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicName topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
for (String element : topicAdminClient.listTopicSubscriptions(topic).iterateAll()) {
// doThingsWith(element);
}
}
topic
- Required. The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
for (String element : topicAdminClient.listTopicSubscriptions(topic).iterateAll()) {
// doThingsWith(element);
}
}
topic
- Required. The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ProjectTopicName topic)
listTopicSubscriptions(TopicName)
instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
topic
- Required. The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ListTopicSubscriptionsRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (String element : topicAdminClient.listTopicSubscriptions(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,TopicAdminClient.ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsPagedCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<String> future =
topicAdminClient.listTopicSubscriptionsPagedCallable().futureCall(request);
// Do something.
for (String element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse> listTopicSubscriptionsCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListTopicSubscriptionsResponse response =
topicAdminClient.listTopicSubscriptionsCallable().call(request);
for (String element : response.getSubscriptionsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final TopicAdminClient.ListTopicSnapshotsPagedResponse listTopicSnapshots(TopicName topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
for (String element : topicAdminClient.listTopicSnapshots(topic).iterateAll()) {
// doThingsWith(element);
}
}
topic
- Required. The name of the topic that snapshots are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicSnapshotsPagedResponse listTopicSnapshots(String topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
for (String element : topicAdminClient.listTopicSnapshots(topic).iterateAll()) {
// doThingsWith(element);
}
}
topic
- Required. The name of the topic that snapshots are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicSnapshotsPagedResponse listTopicSnapshots(ListTopicSnapshotsRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSnapshotsRequest request =
ListTopicSnapshotsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (String element : topicAdminClient.listTopicSnapshots(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListTopicSnapshotsRequest,TopicAdminClient.ListTopicSnapshotsPagedResponse> listTopicSnapshotsPagedCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSnapshotsRequest request =
ListTopicSnapshotsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<String> future =
topicAdminClient.listTopicSnapshotsPagedCallable().futureCall(request);
// Do something.
for (String element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListTopicSnapshotsRequest,ListTopicSnapshotsResponse> listTopicSnapshotsCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicSnapshotsRequest request =
ListTopicSnapshotsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListTopicSnapshotsResponse response =
topicAdminClient.listTopicSnapshotsCallable().call(request);
for (String element : response.getSnapshotsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void deleteTopic(TopicName topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
topic
- Required. Name of the topic to delete. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void deleteTopic(String topic)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
topicAdminClient.deleteTopic(topic);
}
topic
- Required. Name of the topic to delete. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final void deleteTopic(ProjectTopicName topic)
deleteTopic(TopicName)
instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
topic
- Required. Name of the topic to delete. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void deleteTopic(DeleteTopicRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
DeleteTopicRequest request =
DeleteTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
topicAdminClient.deleteTopic(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DeleteTopicRequest,com.google.protobuf.Empty> deleteTopicCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
DeleteTopicRequest request =
DeleteTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
ApiFuture<Empty> future = topicAdminClient.deleteTopicCallable().futureCall(request);
// Do something.
future.get();
}
public final DetachSubscriptionResponse detachSubscription(DetachSubscriptionRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
DetachSubscriptionRequest request =
DetachSubscriptionRequest.newBuilder()
.setSubscription(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString())
.build();
DetachSubscriptionResponse response = topicAdminClient.detachSubscription(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DetachSubscriptionRequest,DetachSubscriptionResponse> detachSubscriptionCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
DetachSubscriptionRequest request =
DetachSubscriptionRequest.newBuilder()
.setSubscription(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString())
.build();
ApiFuture<DetachSubscriptionResponse> future =
topicAdminClient.detachSubscriptionCallable().futureCall(request);
// Do something.
DetachSubscriptionResponse response = future.get();
}
public final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`errors.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder()
.setResource(SchemaName.of("[PROJECT]", "[SCHEMA]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Policy response = topicAdminClient.setIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final com.google.iam.v1.Policy setIamPolicy(String resource, com.google.iam.v1.Policy policy)
setIamPolicy(SetIamPolicyRequest)
instead.Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy policy = Policy.newBuilder().build();
Policy response = topicAdminClient.setIamPolicy(formattedResource, policy);
}
resource
- REQUIRED: The resource for which the policy is being specified. See the
operation documentation for the appropriate value for this field.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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`errors.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder()
.setResource(SchemaName.of("[PROJECT]", "[SCHEMA]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Policy> future = topicAdminClient.setIamPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
GetIamPolicyRequest request =
GetIamPolicyRequest.newBuilder()
.setResource(SchemaName.of("[PROJECT]", "[SCHEMA]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
Policy response = topicAdminClient.getIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final com.google.iam.v1.Policy getIamPolicy(String resource)
getIamPolicy(GetIamPolicyRequest)
instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy response = topicAdminClient.getIamPolicy(formattedResource);
}
resource
- REQUIRED: The resource for which the policy is being requested. See the
operation documentation for the appropriate value for this field.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
GetIamPolicyRequest request =
GetIamPolicyRequest.newBuilder()
.setResource(SchemaName.of("[PROJECT]", "[SCHEMA]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
ApiFuture<Policy> future = topicAdminClient.getIamPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Note: This operation is designed to be used for buildingpermission-aware UIs and command-line tools, not for authorizationchecking. This operation may "fail open" without warning.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(SchemaName.of("[PROJECT]", "[SCHEMA]").toString())
.addAllPermissions(new ArrayList<String>())
.build();
TestIamPermissionsResponse response = topicAdminClient.testIamPermissions(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call fails@Deprecated public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
testIamPermissions(TestIamPermissionsRequest)
instead.Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response = topicAdminClient.testIamPermissions(formattedResource, permissions);
}
resource
- REQUIRED: The resource for which the policy detail is being requested. See the
operation documentation for the appropriate value for this field.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).com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Note: This operation is designed to be used for buildingpermission-aware UIs and command-line tools, not for authorizationchecking. This operation may "fail open" without warning.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(SchemaName.of("[PROJECT]", "[SCHEMA]").toString())
.addAllPermissions(new ArrayList<String>())
.build();
ApiFuture<TestIamPermissionsResponse> future =
topicAdminClient.testIamPermissionsCallable().futureCall(request);
// Do something.
TestIamPermissionsResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2023 Google LLC. All rights reserved.