Class TopicAdminClient (1.118.0)

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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:

  1. 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.
  2. 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.
  3. 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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 TopicAdminSettings topicAdminSettings =
     TopicAdminSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 TopicAdminSettings topicAdminSettings =
     TopicAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
 TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > TopicAdminClient

Implements

BackgroundResource

Static Methods

create()

public static final TopicAdminClient create()

Constructs an instance of TopicAdminClient with default settings.

Returns
TypeDescription
TopicAdminClient
Exceptions
TypeDescription
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
NameDescription
settingsTopicAdminSettings
Returns
TypeDescription
TopicAdminClient
Exceptions
TypeDescription
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
NameDescription
stubPublisherStub
Returns
TypeDescription
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
NameDescription
settingsTopicAdminSettings

TopicAdminClient(PublisherStub stub)

protected TopicAdminClient(PublisherStub stub)
Parameter
NameDescription
stubPublisherStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
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
NameDescription
nameProjectTopicName

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".

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
NameDescription
requestTopic

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   Topic response = topicAdminClient.createTopic(name);
 }
 
Parameter
NameDescription
nameTopicName

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".

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
   Topic response = topicAdminClient.createTopic(name);
 }
 
Parameter
NameDescription
nameString

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".

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   DeleteTopicRequest request =
       DeleteTopicRequest.newBuilder()
           .setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
           .build();
   topicAdminClient.deleteTopic(request);
 }
 
Parameter
NameDescription
requestDeleteTopicRequest

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
NameDescription
topicProjectTopicName

Required. Name of the topic to delete. Format is projects/{project}/topics/{topic}.

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   topicAdminClient.deleteTopic(topic);
 }
 
Parameter
NameDescription
topicTopicName

Required. Name of the topic to delete. Format is projects/{project}/topics/{topic}.

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
   topicAdminClient.deleteTopic(topic);
 }
 
Parameter
NameDescription
topicString

Required. Name of the topic to delete. Format is projects/{project}/topics/{topic}.

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   DetachSubscriptionRequest request =
       DetachSubscriptionRequest.newBuilder()
           .setSubscription(SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]").toString())
           .build();
   DetachSubscriptionResponse response = topicAdminClient.detachSubscription(request);
 }
 
Parameter
NameDescription
requestDetachSubscriptionRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   Policy response = topicAdminClient.getIamPolicy(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.GetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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
NameDescription
resourceString

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   ApiFuture<Policy> future = topicAdminClient.getIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getSettings()

public final TopicAdminSettings getSettings()
Returns
TypeDescription
TopicAdminSettings

getStub()

public PublisherStub getStub()
Returns
TypeDescription
PublisherStub

getTopic(GetTopicRequest request)

public final Topic getTopic(GetTopicRequest request)

Gets the configuration of a topic.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   GetTopicRequest request =
       GetTopicRequest.newBuilder()
           .setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString())
           .build();
   Topic response = topicAdminClient.getTopic(request);
 }
 
Parameter
NameDescription
requestGetTopicRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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
NameDescription
topicProjectTopicName

Required. The name of the topic to get. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
Topic

getTopic(TopicName topic)

public final Topic getTopic(TopicName topic)

Gets the configuration of a topic.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   Topic response = topicAdminClient.getTopic(topic);
 }
 
Parameter
NameDescription
topicTopicName

Required. The name of the topic to get. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
Topic

getTopic(String topic)

public final Topic getTopic(String topic)

Gets the configuration of a topic.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
   Topic response = topicAdminClient.getTopic(topic);
 }
 
Parameter
NameDescription
topicString

Required. The name of the topic to get. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
Topic

getTopicCallable()

public final UnaryCallable<GetTopicRequest,Topic> getTopicCallable()

Gets the configuration of a topic.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
UnaryCallable<GetTopicRequest,Topic>

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
NameDescription
requestListTopicSnapshotsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   for (String element : topicAdminClient.listTopicSnapshots(topic).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
topicTopicName

Required. The name of the topic that snapshots are attached to. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
   for (String element : topicAdminClient.listTopicSnapshots(topic).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
topicString

Required. The name of the topic that snapshots are attached to. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
NameDescription
requestListTopicSubscriptionsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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
NameDescription
topicProjectTopicName

Required. The name of the topic that subscriptions are attached to. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   for (String element : topicAdminClient.listTopicSubscriptions(topic).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
topicTopicName

Required. The name of the topic that subscriptions are attached to. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
   for (String element : topicAdminClient.listTopicSubscriptions(topic).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
topicString

Required. The name of the topic that subscriptions are attached to. Format is projects/{project}/topics/{topic}.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsPagedResponse>

listTopics(ListTopicsRequest request)

public final TopicAdminClient.ListTopicsPagedResponse listTopics(ListTopicsRequest request)

Lists matching topics.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
NameDescription
requestListTopicsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
TopicAdminClient.ListTopicsPagedResponse

listTopics(ProjectName project)

public final TopicAdminClient.ListTopicsPagedResponse listTopics(ProjectName project)

Lists matching topics.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   ProjectName project = ProjectName.of("[PROJECT]");
   for (Topic element : topicAdminClient.listTopics(project).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
projectProjectName

Required. The name of the project in which to list topics. Format is projects/{project-id}.

Returns
TypeDescription
TopicAdminClient.ListTopicsPagedResponse

listTopics(String project)

public final TopicAdminClient.ListTopicsPagedResponse listTopics(String project)

Lists matching topics.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String project = ProjectName.of("[PROJECT]").toString();
   for (Topic element : topicAdminClient.listTopics(project).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
projectString

Required. The name of the project in which to list topics. Format is projects/{project-id}.

Returns
TypeDescription
TopicAdminClient.ListTopicsPagedResponse

listTopicsCallable()

public final UnaryCallable<ListTopicsRequest,ListTopicsResponse> listTopicsCallable()

Lists matching topics.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListTopicsRequest,ListTopicsResponse>

listTopicsPagedCallable()

public final UnaryCallable<ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> listTopicsPagedCallable()

Lists matching topics.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
NameDescription
requestPublishRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   List<PubsubMessage> messages = new ArrayList<>();
   PublishResponse response = topicAdminClient.publish(topic, messages);
 }
 
Parameters
NameDescription
topicTopicName

Required. The messages in the request will be published on this topic. Format is projects/{project}/topics/{topic}.

messagesList<PubsubMessage>

Required. The messages to publish.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   String topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString();
   List<PubsubMessage> messages = new ArrayList<>();
   PublishResponse response = topicAdminClient.publish(topic, messages);
 }
 
Parameters
NameDescription
topicString

Required. The messages in the request will be published on this topic. Format is projects/{project}/topics/{topic}.

messagesList<PubsubMessage>

Required. The messages to publish.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
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_DENIEDerrors.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setPolicy(Policy.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Policy response = topicAdminClient.setIamPolicy(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.SetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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
NameDescription
resourceString

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policycom.google.iam.v1.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.

Returns
TypeDescription
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_DENIEDerrors.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .setPolicy(Policy.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Policy> future = topicAdminClient.setIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TestIamPermissionsRequest request =
       TestIamPermissionsRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .addAllPermissions(new ArrayList<String>())
           .build();
   TestIamPermissionsResponse response = topicAdminClient.testIamPermissions(request);
 }
 
Parameter
NameDescription
requestcom.google.iam.v1.TestIamPermissionsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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
NameDescription
resourceString

REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

permissionsList<String>

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.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TestIamPermissionsRequest request =
       TestIamPermissionsRequest.newBuilder()
           .setResource(ProjectName.of("[PROJECT]").toString())
           .addAllPermissions(new ArrayList<String>())
           .build();
   ApiFuture<TestIamPermissionsResponse> future =
       topicAdminClient.testIamPermissionsCallable().futureCall(request);
   // Do something.
   TestIamPermissionsResponse response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse>

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   UpdateTopicRequest request =
       UpdateTopicRequest.newBuilder()
           .setTopic(Topic.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Topic response = topicAdminClient.updateTopic(request);
 }
 
Parameter
NameDescription
requestUpdateTopicRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 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
TypeDescription
UnaryCallable<UpdateTopicRequest,Topic>