@Generated(value="by gapic-generator") public class TopicAdminClient extends Object implements com.google.api.gax.core.BackgroundResource
To publish messages to a topic, see the Publisher class.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
Note: close() needs to be called on the topicAdminClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of TopicAdminSettings to create(). For example:
To customize credentials:
TopicAdminSettings topicAdminSettings =
TopicAdminSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TopicAdminClient topicAdminClient =
TopicAdminClient.create(topicAdminSettings);
To customize the endpoint:
TopicAdminSettings topicAdminSettings =
TopicAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
TopicAdminClient topicAdminClient =
TopicAdminClient.create(topicAdminSettings);
| Modifier and Type | Class and Description |
|---|---|
static class |
TopicAdminClient.ListTopicsFixedSizeCollection |
static class |
TopicAdminClient.ListTopicsPage |
static class |
TopicAdminClient.ListTopicsPagedResponse |
static class |
TopicAdminClient.ListTopicSubscriptionsFixedSizeCollection |
static class |
TopicAdminClient.ListTopicSubscriptionsPage |
static class |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
| Modifier | Constructor and Description |
|---|---|
protected |
TopicAdminClient(PublisherStub stub) |
protected |
TopicAdminClient(TopicAdminSettings settings)
Constructs an instance of TopicAdminClient, using the given settings.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static TopicAdminClient |
create()
Constructs an instance of TopicAdminClient with default settings.
|
static TopicAdminClient |
create(PublisherStub stub)
Constructs an instance of TopicAdminClient, using the given stub for making calls.
|
static TopicAdminClient |
create(TopicAdminSettings settings)
Constructs an instance of TopicAdminClient, using the given settings.
|
Topic |
createTopic(ProjectTopicName name)
Deprecated.
Use
createTopic(TopicName) instead. |
Topic |
createTopic(String name)
Creates the given topic with the given name.
|
Topic |
createTopic(Topic request)
Creates the given topic with the given name.
|
Topic |
createTopic(TopicName name)
Creates the given topic with the given name.
|
com.google.api.gax.rpc.UnaryCallable<Topic,Topic> |
createTopicCallable()
Creates the given topic with the given name.
|
void |
deleteTopic(DeleteTopicRequest request)
Deletes the topic with the given name.
|
void |
deleteTopic(ProjectTopicName topic)
Deprecated.
Use
deleteTopic(TopicName) instead. |
void |
deleteTopic(String topic)
Deletes the topic with the given name.
|
void |
deleteTopic(TopicName topic)
Deletes the topic with the given name.
|
com.google.api.gax.rpc.UnaryCallable<DeleteTopicRequest,com.google.protobuf.Empty> |
deleteTopicCallable()
Deletes the topic with the given name.
|
com.google.iam.v1.Policy |
getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Gets the access control policy for a resource.
|
com.google.iam.v1.Policy |
getIamPolicy(String resource)
Deprecated.
Use
getIamPolicy(GetIamPolicyRequest) instead. |
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Gets the access control policy for a resource.
|
TopicAdminSettings |
getSettings() |
PublisherStub |
getStub() |
Topic |
getTopic(GetTopicRequest request)
Gets the configuration of a topic.
|
Topic |
getTopic(ProjectTopicName topic)
Deprecated.
Use
getTopic(TopicName) instead. |
Topic |
getTopic(String topic)
Gets the configuration of a topic.
|
Topic |
getTopic(TopicName topic)
Gets the configuration of a topic.
|
com.google.api.gax.rpc.UnaryCallable<GetTopicRequest,Topic> |
getTopicCallable()
Gets the configuration of a topic.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
TopicAdminClient.ListTopicsPagedResponse |
listTopics(ListTopicsRequest request)
Lists matching topics.
|
TopicAdminClient.ListTopicsPagedResponse |
listTopics(ProjectName project)
Lists matching topics.
|
TopicAdminClient.ListTopicsPagedResponse |
listTopics(String project)
Lists matching topics.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,ListTopicsResponse> |
listTopicsCallable()
Lists matching topics.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> |
listTopicsPagedCallable()
Lists matching topics.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(ListTopicSubscriptionsRequest request)
Lists the names of the subscriptions on this topic.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(ProjectTopicName topic)
Deprecated.
Use
listTopicSubscriptions(TopicName) instead. |
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(String topic)
Lists the names of the subscriptions on this topic.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(TopicName topic)
Lists the names of the subscriptions on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse> |
listTopicSubscriptionsCallable()
Lists the names of the subscriptions on this topic.
|
com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,TopicAdminClient.ListTopicSubscriptionsPagedResponse> |
listTopicSubscriptionsPagedCallable()
Lists the names of the subscriptions on this topic.
|
com.google.iam.v1.Policy |
setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sets the access control policy on the specified resource.
|
com.google.iam.v1.Policy |
setIamPolicy(String resource,
com.google.iam.v1.Policy policy)
Deprecated.
Use
setIamPolicy(SetIamPolicyRequest) instead. |
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> |
setIamPolicyCallable()
Sets the access control policy on the specified resource.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(String resource,
List<String> permissions)
Deprecated.
Use
testIamPermissions(TestIamPermissionsRequest) instead. |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on the specified resource.
|
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that a caller has on the specified resource.
|
Topic |
updateTopic(UpdateTopicRequest request)
Updates an existing topic.
|
com.google.api.gax.rpc.UnaryCallable<UpdateTopicRequest,Topic> |
updateTopicCallable()
Updates an existing topic.
|
protected TopicAdminClient(TopicAdminSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected TopicAdminClient(PublisherStub stub)
public static final TopicAdminClient create() throws IOException
IOExceptionpublic static final TopicAdminClient create(TopicAdminSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final TopicAdminClient create(PublisherStub stub)
public final TopicAdminSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public PublisherStub getStub()
public final Topic createTopic(TopicName name)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
name - Required. The name of the topic. It must have the format
`"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, and contain only
letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`),
tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters in
length, and it must not start with `"goog"`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Topic createTopic(String name)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name.toString());
}
name - Required. The name of the topic. It must have the format
`"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, and contain only
letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`),
tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters in
length, and it must not start with `"goog"`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Topic createTopic(ProjectTopicName name)
createTopic(TopicName) instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
name - Required. The name of the topic. It must have the format
`"projects/{project}/topics/{topic}"`. `{topic}` must start with a letter, and contain only
letters (`[A-Za-z]`), numbers (`[0-9]`), dashes (`-`), underscores (`_`), periods (`.`),
tildes (`~`), plus (`+`) or percent signs (`%`). It must be between 3 and 255 characters in
length, and it must not start with `"goog"`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Topic createTopic(Topic request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic request = Topic.newBuilder()
.setName(name.toString())
.build();
Topic response = topicAdminClient.createTopic(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<Topic,Topic> createTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic request = Topic.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Topic> future = topicAdminClient.createTopicCallable().futureCall(request);
// Do something
Topic response = future.get();
}
public final Topic updateTopic(UpdateTopicRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic topic = Topic.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
UpdateTopicRequest request = UpdateTopicRequest.newBuilder()
.setTopic(topic)
.setUpdateMask(updateMask)
.build();
Topic response = topicAdminClient.updateTopic(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<UpdateTopicRequest,Topic> updateTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
Topic topic = Topic.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
UpdateTopicRequest request = UpdateTopicRequest.newBuilder()
.setTopic(topic)
.setUpdateMask(updateMask)
.build();
ApiFuture<Topic> future = topicAdminClient.updateTopicCallable().futureCall(request);
// Do something
Topic response = future.get();
}
public final Topic getTopic(TopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
topic - Required. The name of the topic to get. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Topic getTopic(String topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic.toString());
}
topic - Required. The name of the topic to get. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Topic getTopic(ProjectTopicName topic)
getTopic(TopicName) instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
topic - Required. The name of the topic to get. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final Topic getTopic(GetTopicRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
GetTopicRequest request = GetTopicRequest.newBuilder()
.setTopic(topic.toString())
.build();
Topic response = topicAdminClient.getTopic(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetTopicRequest,Topic> getTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
GetTopicRequest request = GetTopicRequest.newBuilder()
.setTopic(topic.toString())
.build();
ApiFuture<Topic> future = topicAdminClient.getTopicCallable().futureCall(request);
// Do something
Topic response = future.get();
}
public final TopicAdminClient.ListTopicsPagedResponse listTopics(ProjectName project)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Topic element : topicAdminClient.listTopics(project).iterateAll()) {
// doThingsWith(element);
}
}
project - Required. The name of the project in which to list topics. Format is
`projects/{project-id}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TopicAdminClient.ListTopicsPagedResponse listTopics(String project)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Topic element : topicAdminClient.listTopics(project.toString()).iterateAll()) {
// doThingsWith(element);
}
}
project - Required. The name of the project in which to list topics. Format is
`projects/{project-id}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TopicAdminClient.ListTopicsPagedResponse listTopics(ListTopicsRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListTopicsRequest request = ListTopicsRequest.newBuilder()
.setProject(project.toString())
.build();
for (Topic element : topicAdminClient.listTopics(request).iterateAll()) {
// doThingsWith(element);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> listTopicsPagedCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListTopicsRequest request = ListTopicsRequest.newBuilder()
.setProject(project.toString())
.build();
ApiFuture<ListTopicsPagedResponse> future = topicAdminClient.listTopicsPagedCallable().futureCall(request);
// Do something
for (Topic element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListTopicsRequest,ListTopicsResponse> listTopicsCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListTopicsRequest request = ListTopicsRequest.newBuilder()
.setProject(project.toString())
.build();
while (true) {
ListTopicsResponse response = topicAdminClient.listTopicsCallable().call(request);
for (Topic element : response.getTopicsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
topic - Required. The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic.toString()).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
topic - Required. The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ProjectTopicName topic)
listTopicSubscriptions(TopicName) instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
topic - Required. The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ListTopicSubscriptionsRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
.setTopic(topic.toString())
.build();
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(request).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,TopicAdminClient.ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsPagedCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
.setTopic(topic.toString())
.build();
ApiFuture<ListTopicSubscriptionsPagedResponse> future = topicAdminClient.listTopicSubscriptionsPagedCallable().futureCall(request);
// Do something
for (ProjectSubscriptionName element : future.get().iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListTopicSubscriptionsRequest,ListTopicSubscriptionsResponse> listTopicSubscriptionsCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
.setTopic(topic.toString())
.build();
while (true) {
ListTopicSubscriptionsResponse response = topicAdminClient.listTopicSubscriptionsCallable().call(request);
for (ProjectSubscriptionName element : ProjectSubscriptionName.parseList(response.getSubscriptionsList())) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void deleteTopic(TopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
topic - Required. Name of the topic to delete. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteTopic(String topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic.toString());
}
topic - Required. Name of the topic to delete. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteTopic(ProjectTopicName topic)
deleteTopic(TopicName) instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
topic - Required. Name of the topic to delete. Format is
`projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final void deleteTopic(DeleteTopicRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
.setTopic(topic.toString())
.build();
topicAdminClient.deleteTopic(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DeleteTopicRequest,com.google.protobuf.Empty> deleteTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
.setTopic(topic.toString())
.build();
ApiFuture<Void> future = topicAdminClient.deleteTopicCallable().futureCall(request);
// Do something
future.get();
}
public final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.setPolicy(policy)
.build();
Policy response = topicAdminClient.setIamPolicy(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.iam.v1.Policy setIamPolicy(String resource, com.google.iam.v1.Policy policy)
setIamPolicy(SetIamPolicyRequest) instead.Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy policy = Policy.newBuilder().build();
Policy response = topicAdminClient.setIamPolicy(formattedResource, policy);
}
resource - REQUIRED: The resource for which the policy is being specified. See the
operation documentation for the appropriate value for this field.policy - REQUIRED: The complete policy to be applied to the `resource`. The size of the
policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
Platform services (such as Projects) might reject them.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.setPolicy(policy)
.build();
ApiFuture<Policy> future = topicAdminClient.setIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.build();
Policy response = topicAdminClient.getIamPolicy(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.iam.v1.Policy getIamPolicy(String resource)
getIamPolicy(GetIamPolicyRequest) instead.Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy response = topicAdminClient.getIamPolicy(formattedResource);
}
resource - REQUIRED: The resource for which the policy is being requested. See the
operation documentation for the appropriate value for this field.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.build();
ApiFuture<Policy> future = topicAdminClient.getIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Note: This operation is designed to be used for 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()) {
ResourceName resource = ProjectName.of("[PROJECT]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(resource.toString())
.addAllPermissions(permissions)
.build();
TestIamPermissionsResponse response = topicAdminClient.testIamPermissions(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
testIamPermissions(TestIamPermissionsRequest) instead.Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response = topicAdminClient.testIamPermissions(formattedResource, permissions);
}
resource - REQUIRED: The resource for which the policy detail is being requested. See the
operation documentation for the appropriate value for this field.permissions - The set of permissions to check for the `resource`. Permissions with
wildcards (such as '*' or 'storage.*') are not allowed. For more information see
[IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Note: This operation is designed to be used for 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()) {
ResourceName resource = ProjectName.of("[PROJECT]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(resource.toString())
.addAllPermissions(permissions)
.build();
ApiFuture<TestIamPermissionsResponse> future = topicAdminClient.testIamPermissionsCallable().futureCall(request);
// Do something
TestIamPermissionsResponse response = future.get();
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2020 Google LLC. All rights reserved.