public class TopicAdminClient implements BackgroundResource
Service Description: The service that an application uses to manipulate topics, and to send messages to a topic.
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:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
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.
Implements
BackgroundResourceStatic Methods
create()
public static final TopicAdminClient create()
Constructs an instance of TopicAdminClient with default settings.
Returns | |
---|---|
Type | Description |
TopicAdminClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(TopicAdminSettings settings)
public static final TopicAdminClient create(TopicAdminSettings settings)
Constructs an instance of TopicAdminClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
Parameter | |
---|---|
Name | Description |
settings | TopicAdminSettings |
Returns | |
---|---|
Type | Description |
TopicAdminClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(PublisherStub stub)
public static final TopicAdminClient create(PublisherStub stub)
Constructs an instance of TopicAdminClient, using the given stub for making calls. This is for advanced usage - prefer using create(TopicAdminSettings).
Parameter | |
---|---|
Name | Description |
stub | PublisherStub |
Returns | |
---|---|
Type | Description |
TopicAdminClient |
Constructors
TopicAdminClient(TopicAdminSettings settings)
protected TopicAdminClient(TopicAdminSettings settings)
Constructs an instance of TopicAdminClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
Parameter | |
---|---|
Name | Description |
settings | TopicAdminSettings |
TopicAdminClient(PublisherStub stub)
protected TopicAdminClient(PublisherStub stub)
Parameter | |
---|---|
Name | Description |
stub | PublisherStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)
Parameters | |
---|---|
Name | Description |
duration | long |
unit | TimeUnit |
Returns | |
---|---|
Type | Description |
boolean |
Exceptions | |
---|---|
Type | Description |
InterruptedException |
close()
public final void close()
createTopic(ProjectTopicName name) (deprecated)
public final Topic createTopic(ProjectTopicName name)
Deprecated. Use #createTopic(TopicName) instead.
Creates the given topic with the given name. See the <a href="https://cloud.google.com/pubsub/docs/admin#resource_names">; resource name rules</a>.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
Parameter | |
---|---|
Name | Description |
name | ProjectTopicName Required. The name of the topic. It must have the format
|
Returns | |
---|---|
Type | Description |
Topic |
createTopic(Topic request)
public final Topic createTopic(Topic request)
Creates the given topic with the given name. See the resource name rules.
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);
}
Parameter | |
---|---|
Name | Description |
request | Topic The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
Topic |
createTopic(TopicName name)
public final Topic createTopic(TopicName name)
Creates the given topic with the given name. See the resource name rules.
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);
}
Parameter | |
---|---|
Name | Description |
name | TopicName Required. The name of the topic. It must have the format
|
Returns | |
---|---|
Type | Description |
Topic |
createTopic(String name)
public final Topic createTopic(String name)
Creates the given topic with the given name. See the resource name rules.
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);
}
Parameter | |
---|---|
Name | Description |
name | String Required. The name of the topic. It must have the format
|
Returns | |
---|---|
Type | Description |
Topic |
createTopicCallable()
public final UnaryCallable<Topic,Topic> createTopicCallable()
Creates the given topic with the given name. See the resource name rules.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<Topic,Topic> |
deleteTopic(DeleteTopicRequest request)
public final void deleteTopic(DeleteTopicRequest request)
Deletes the topic with the given name. Returns NOT_FOUND
if the topic does not exist. After a
topic is deleted, a new topic may be created with the same name; this is an entirely new topic
with none of the old configuration or subscriptions. Existing subscriptions to this topic are
not deleted, but their topic
field is set to deleted-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()) {
DeleteTopicRequest request =
DeleteTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
topicAdminClient.deleteTopic(request);
}
Parameter | |
---|---|
Name | Description |
request | DeleteTopicRequest The request object containing all of the parameters for the API call. |
deleteTopic(ProjectTopicName topic) (deprecated)
public final void deleteTopic(ProjectTopicName topic)
Deprecated. Use #deleteTopic(TopicName) instead.
Deletes the topic with the given name. Returns NOT_FOUND
if the topic does not exist. After a
topic is deleted, a new topic may be created with the same name; this is an entirely new topic
with none of the old configuration or subscriptions. Existing subscriptions to this topic are
not deleted, but their topic
field is set to deleted-topic
.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
Parameter | |
---|---|
Name | Description |
topic | ProjectTopicName Required. Name of the topic to delete. Format is
|
deleteTopic(TopicName topic)
public final void deleteTopic(TopicName topic)
Deletes the topic with the given name. Returns NOT_FOUND
if the topic does not exist. After a
topic is deleted, a new topic may be created with the same name; this is an entirely new topic
with none of the old configuration or subscriptions. Existing subscriptions to this topic are
not deleted, but their topic
field is set to deleted-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);
}
Parameter | |
---|---|
Name | Description |
topic | TopicName Required. Name of the topic to delete. Format is
|
deleteTopic(String topic)
public final void deleteTopic(String topic)
Deletes the topic with the given name. Returns NOT_FOUND
if the topic does not exist. After a
topic is deleted, a new topic may be created with the same name; this is an entirely new topic
with none of the old configuration or subscriptions. Existing subscriptions to this topic are
not deleted, but their topic
field is set to deleted-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);
}
Parameter | |
---|---|
Name | Description |
topic | String Required. Name of the topic to delete. Format is
|
deleteTopicCallable()
public final UnaryCallable<DeleteTopicRequest,Empty> deleteTopicCallable()
Deletes the topic with the given name. Returns NOT_FOUND
if the topic does not exist. After a
topic is deleted, a new topic may be created with the same name; this is an entirely new topic
with none of the old configuration or subscriptions. Existing subscriptions to this topic are
not deleted, but their topic
field is set to deleted-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()) {
DeleteTopicRequest request =
DeleteTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
ApiFuture<Empty> future = topicAdminClient.deleteTopicCallable().futureCall(request);
// Do something.
future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<DeleteTopicRequest,Empty> |
detachSubscription(DetachSubscriptionRequest request)
public final DetachSubscriptionResponse detachSubscription(DetachSubscriptionRequest request)
Detaches a subscription from this topic. All messages retained in the subscription are dropped.
Subsequent Pull
and StreamingPull
requests will return FAILED_PRECONDITION. If the
subscription is a push subscription, pushes to the endpoint will stop.
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);
}
Parameter | |
---|---|
Name | Description |
request | DetachSubscriptionRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
DetachSubscriptionResponse |
detachSubscriptionCallable()
public final UnaryCallable<DetachSubscriptionRequest,DetachSubscriptionResponse> detachSubscriptionCallable()
Detaches a subscription from this topic. All messages retained in the subscription are dropped.
Subsequent Pull
and StreamingPull
requests will return FAILED_PRECONDITION. If the
subscription is a push subscription, pushes to the endpoint will stop.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<DetachSubscriptionRequest,DetachSubscriptionResponse> |
getIamPolicy(GetIamPolicyRequest request)
public final Policy getIamPolicy(GetIamPolicyRequest request)
Gets the access control policy for a resource. Returns an empty policyif the resource exists and does not have a policy set.
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);
}
Parameter | |
---|---|
Name | Description |
request | com.google.iam.v1.GetIamPolicyRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
com.google.iam.v1.Policy |
getIamPolicy(String resource) (deprecated)
public final Policy getIamPolicy(String resource)
Deprecated. Use #getIamPolicy(GetIamPolicyRequest) instead.
Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy response = topicAdminClient.getIamPolicy(formattedResource);
}
Parameter | |
---|---|
Name | Description |
resource | String REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field. |
Returns | |
---|---|
Type | Description |
com.google.iam.v1.Policy |
getIamPolicyCallable()
public final UnaryCallable<GetIamPolicyRequest,Policy> getIamPolicyCallable()
Gets the access control policy for a resource. Returns an empty policyif the resource exists and does not have a policy set.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getSettings()
public final TopicAdminSettings getSettings()
Returns | |
---|---|
Type | Description |
TopicAdminSettings |
getStub()
public PublisherStub getStub()
Returns | |
---|---|
Type | Description |
PublisherStub |
getTopic(GetTopicRequest request)
public final Topic getTopic(GetTopicRequest request)
Gets the configuration of a 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()) {
GetTopicRequest request =
GetTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
Topic response = topicAdminClient.getTopic(request);
}
Parameter | |
---|---|
Name | Description |
request | GetTopicRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
Topic |
getTopic(ProjectTopicName topic) (deprecated)
public final Topic getTopic(ProjectTopicName topic)
Deprecated. Use #getTopic(TopicName) instead.
Gets the configuration of a topic.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
Parameter | |
---|---|
Name | Description |
topic | ProjectTopicName Required. The name of the topic to get. Format is
|
Returns | |
---|---|
Type | Description |
Topic |
getTopic(TopicName topic)
public final Topic getTopic(TopicName topic)
Gets the configuration of a 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);
}
Parameter | |
---|---|
Name | Description |
topic | TopicName Required. The name of the topic to get. Format is
|
Returns | |
---|---|
Type | Description |
Topic |
getTopic(String topic)
public final Topic getTopic(String topic)
Gets the configuration of a 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);
}
Parameter | |
---|---|
Name | Description |
topic | String Required. The name of the topic to get. Format is
|
Returns | |
---|---|
Type | Description |
Topic |
getTopicCallable()
public final UnaryCallable<GetTopicRequest,Topic> getTopicCallable()
Gets the configuration of a 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()) {
GetTopicRequest request =
GetTopicRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.build();
ApiFuture<Topic> future = topicAdminClient.getTopicCallable().futureCall(request);
// Do something.
Topic response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<GetTopicRequest,Topic> |
isShutdown()
public boolean isShutdown()
Returns | |
---|---|
Type | Description |
boolean |
isTerminated()
public boolean isTerminated()
Returns | |
---|---|
Type | Description |
boolean |
listTopicSnapshots(ListTopicSnapshotsRequest request)
public final TopicAdminClient.ListTopicSnapshotsPagedResponse listTopicSnapshots(ListTopicSnapshotsRequest request)
Lists the names of the snapshots on this topic. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
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);
}
}
Parameter | |
---|---|
Name | Description |
request | ListTopicSnapshotsRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSnapshotsPagedResponse |
listTopicSnapshots(TopicName topic)
public final TopicAdminClient.ListTopicSnapshotsPagedResponse listTopicSnapshots(TopicName topic)
Lists the names of the snapshots on this topic. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
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);
}
}
Parameter | |
---|---|
Name | Description |
topic | TopicName Required. The name of the topic that snapshots are attached to. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSnapshotsPagedResponse |
listTopicSnapshots(String topic)
public final TopicAdminClient.ListTopicSnapshotsPagedResponse listTopicSnapshots(String topic)
Lists the names of the snapshots on this topic. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
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);
}
}
Parameter | |
---|---|
Name | Description |
topic | String Required. The name of the topic that snapshots are attached to. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSnapshotsPagedResponse |
listTopicSnapshotsCallable()
public final UnaryCallable<ListTopicSnapshotsRequest,ListTopicSnapshotsResponse> listTopicSnapshotsCallable()
Lists the names of the snapshots on this topic. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
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;
}
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListTopicSnapshotsRequest,ListTopicSnapshotsResponse> |
listTopicSnapshotsPagedCallable()
public final UnaryCallable<ListTopicSnapshotsRequest,TopicAdminClient.ListTopicSnapshotsPagedResponse> listTopicSnapshotsPagedCallable()
Lists the names of the snapshots on this topic. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
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);
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListTopicSnapshotsRequest,ListTopicSnapshotsPagedResponse> |
listTopicSubscriptions(ListTopicSubscriptionsRequest request)
public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ListTopicSubscriptionsRequest request)
Lists the names of the attached subscriptions on this 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()) {
ListTopicSubscriptionsRequest request =
ListTopicSubscriptionsRequest.newBuilder()
.setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (String element : topicAdminClient.listTopicSubscriptions(request).iterateAll()) {
// doThingsWith(element);
}
}
Parameter | |
---|---|
Name | Description |
request | ListTopicSubscriptionsRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(ProjectTopicName topic) (deprecated)
public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ProjectTopicName topic)
Deprecated. Use #listTopicSubscriptions(TopicName) instead.
Lists the names of the subscriptions on this topic.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
Parameter | |
---|---|
Name | Description |
topic | ProjectTopicName Required. The name of the topic that subscriptions are attached to. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(TopicName topic)
public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicName topic)
Lists the names of the attached subscriptions on this 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);
}
}
Parameter | |
---|---|
Name | Description |
topic | TopicName Required. The name of the topic that subscriptions are attached to. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(String topic)
public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topic)
Lists the names of the attached subscriptions on this 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);
}
}
Parameter | |
---|---|
Name | Description |
topic | String Required. The name of the topic that subscriptions are attached to. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptionsCallable()
public final UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse> listTopicSubscriptionsCallable()
Lists the names of the attached subscriptions on this 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()) {
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;
}
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse> |
listTopicSubscriptionsPagedCallable()
public final UnaryCallable<ListTopicSubscriptionsRequest,TopicAdminClient.ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsPagedCallable()
Lists the names of the attached subscriptions on this 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()) {
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);
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsPagedResponse> |
listTopics(ListTopicsRequest request)
public final TopicAdminClient.ListTopicsPagedResponse listTopics(ListTopicsRequest request)
Lists matching topics.
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);
}
}
Parameter | |
---|---|
Name | Description |
request | ListTopicsRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicsPagedResponse |
listTopics(ProjectName project)
public final TopicAdminClient.ListTopicsPagedResponse listTopics(ProjectName project)
Lists matching topics.
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);
}
}
Parameter | |
---|---|
Name | Description |
project | ProjectName Required. The name of the project in which to list topics. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicsPagedResponse |
listTopics(String project)
public final TopicAdminClient.ListTopicsPagedResponse listTopics(String project)
Lists matching topics.
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);
}
}
Parameter | |
---|---|
Name | Description |
project | String Required. The name of the project in which to list topics. Format is
|
Returns | |
---|---|
Type | Description |
TopicAdminClient.ListTopicsPagedResponse |
listTopicsCallable()
public final UnaryCallable<ListTopicsRequest,ListTopicsResponse> listTopicsCallable()
Lists matching topics.
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;
}
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListTopicsRequest,ListTopicsResponse> |
listTopicsPagedCallable()
public final UnaryCallable<ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> listTopicsPagedCallable()
Lists matching topics.
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);
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListTopicsRequest,ListTopicsPagedResponse> |
publish(PublishRequest request)
public final PublishResponse publish(PublishRequest request)
Adds one or more messages to the topic. Returns NOT_FOUND
if the topic does not exist.
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);
}
Parameter | |
---|---|
Name | Description |
request | PublishRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
PublishResponse |
publish(TopicName topic, List<PubsubMessage> messages)
public final PublishResponse publish(TopicName topic, List<PubsubMessage> messages)
Adds one or more messages to the topic. Returns NOT_FOUND
if the topic does not exist.
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);
}
Parameters | |
---|---|
Name | Description |
topic | TopicName Required. The messages in the request will be published on this topic. Format is
|
messages | List<PubsubMessage> Required. The messages to publish. |
Returns | |
---|---|
Type | Description |
PublishResponse |
publish(String topic, List<PubsubMessage> messages)
public final PublishResponse publish(String topic, List<PubsubMessage> messages)
Adds one or more messages to the topic. Returns NOT_FOUND
if the topic does not exist.
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);
}
Parameters | |
---|---|
Name | Description |
topic | String Required. The messages in the request will be published on this topic. Format is
|
messages | List<PubsubMessage> Required. The messages to publish. |
Returns | |
---|---|
Type | Description |
PublishResponse |
publishCallable()
public final UnaryCallable<PublishRequest,PublishResponse> publishCallable()
Adds one or more messages to the topic. Returns NOT_FOUND
if the topic does not exist.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<PublishRequest,PublishResponse> |
setIamPolicy(SetIamPolicyRequest request)
public final Policy setIamPolicy(SetIamPolicyRequest request)
Sets the access control policy on the specified resource. Replacesany existing policy.
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);
}
Parameter | |
---|---|
Name | Description |
request | com.google.iam.v1.SetIamPolicyRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
com.google.iam.v1.Policy |
setIamPolicy(String resource, Policy policy) (deprecated)
public final Policy setIamPolicy(String resource, Policy policy)
Deprecated. Use #setIamPolicy(SetIamPolicyRequest) instead.
Sets the access control policy on the specified resource. Replaces any existing policy.
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);
}
Parameters | |
---|---|
Name | Description |
resource | String REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field. |
policy | com.google.iam.v1.Policy REQUIRED: The complete policy to be applied to the |
Returns | |
---|---|
Type | Description |
com.google.iam.v1.Policy |
setIamPolicyCallable()
public final UnaryCallable<SetIamPolicyRequest,Policy> setIamPolicyCallable()
Sets the access control policy on the specified resource. Replacesany existing policy.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> |
shutdown()
public void shutdown()
shutdownNow()
public void shutdownNow()
testIamPermissions(TestIamPermissionsRequest request)
public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request)
Returns permissions that a caller has on the specified resource. If theresource does not exist,
this will return an empty set ofpermissions, not a NOT_FOUND
error.
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);
}
Parameter | |
---|---|
Name | Description |
request | com.google.iam.v1.TestIamPermissionsRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(String resource, List<String> permissions) (deprecated)
public final TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
Deprecated. Use #testIamPermissions(TestIamPermissionsRequest) instead.
Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.
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);
}
Parameters | |
---|---|
Name | Description |
resource | String REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field. |
permissions | List<String> The set of permissions to check for the |
Returns | |
---|---|
Type | Description |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissionsCallable()
public final UnaryCallable<TestIamPermissionsRequest,TestIamPermissionsResponse> testIamPermissionsCallable()
Returns permissions that a caller has on the specified resource. If theresource does not exist,
this will return an empty set ofpermissions, not a NOT_FOUND
error.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
updateTopic(Topic topic, FieldMask updateMask)
public final Topic updateTopic(Topic topic, FieldMask updateMask)
Updates an existing topic. Note that certain properties of a topic are not modifiable.
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);
}
Parameters | |
---|---|
Name | Description |
topic | Topic Required. The updated topic object. |
updateMask | FieldMask Required. Indicates which fields in the provided topic to update. Must be
specified and non-empty. Note that if |
Returns | |
---|---|
Type | Description |
Topic |
updateTopic(UpdateTopicRequest request)
public final Topic updateTopic(UpdateTopicRequest request)
Updates an existing topic. Note that certain properties of a topic are not modifiable.
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);
}
Parameter | |
---|---|
Name | Description |
request | UpdateTopicRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
Topic |
updateTopicCallable()
public final UnaryCallable<UpdateTopicRequest,Topic> updateTopicCallable()
Updates an existing topic. Note that certain properties of a topic are not modifiable.
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();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<UpdateTopicRequest,Topic> |