@Generated(value="by gapic-generator") public class TopicAdminClient extends Object implements 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()) {
ProjectTopicName name = ProjectTopicName.of("[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.
|
com.google.pubsub.v1.Topic |
createTopic(com.google.pubsub.v1.ProjectTopicName name)
Creates the given topic with the given name.
|
com.google.pubsub.v1.Topic |
createTopic(String name)
Creates the given topic with the given name.
|
com.google.pubsub.v1.Topic |
createTopic(com.google.pubsub.v1.Topic request)
Creates the given topic with the given name.
|
UnaryCallable<com.google.pubsub.v1.Topic,com.google.pubsub.v1.Topic> |
createTopicCallable()
Creates the given topic with the given name.
|
void |
deleteTopic(com.google.pubsub.v1.DeleteTopicRequest request)
Deletes the topic with the given name.
|
void |
deleteTopic(com.google.pubsub.v1.ProjectTopicName topic)
Deletes the topic with the given name.
|
void |
deleteTopic(String topic)
Deletes the topic with the given name.
|
UnaryCallable<com.google.pubsub.v1.DeleteTopicRequest,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)
Gets the access control policy for a resource.
|
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Gets the access control policy for a resource.
|
TopicAdminSettings |
getSettings() |
PublisherStub |
getStub() |
com.google.pubsub.v1.Topic |
getTopic(com.google.pubsub.v1.GetTopicRequest request)
Gets the configuration of a topic.
|
com.google.pubsub.v1.Topic |
getTopic(com.google.pubsub.v1.ProjectTopicName topic)
Gets the configuration of a topic.
|
com.google.pubsub.v1.Topic |
getTopic(String topic)
Gets the configuration of a topic.
|
UnaryCallable<com.google.pubsub.v1.GetTopicRequest,com.google.pubsub.v1.Topic> |
getTopicCallable()
Gets the configuration of a topic.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
TopicAdminClient.ListTopicsPagedResponse |
listTopics(com.google.pubsub.v1.ListTopicsRequest request)
Lists matching topics.
|
TopicAdminClient.ListTopicsPagedResponse |
listTopics(com.google.pubsub.v1.ProjectName project)
Lists matching topics.
|
TopicAdminClient.ListTopicsPagedResponse |
listTopics(String project)
Lists matching topics.
|
UnaryCallable<com.google.pubsub.v1.ListTopicsRequest,com.google.pubsub.v1.ListTopicsResponse> |
listTopicsCallable()
Lists matching topics.
|
UnaryCallable<com.google.pubsub.v1.ListTopicsRequest,TopicAdminClient.ListTopicsPagedResponse> |
listTopicsPagedCallable()
Lists matching topics.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(com.google.pubsub.v1.ListTopicSubscriptionsRequest request)
Lists the names of the subscriptions on this topic.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(com.google.pubsub.v1.ProjectTopicName topic)
Lists the names of the subscriptions on this topic.
|
TopicAdminClient.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(String topic)
Lists the names of the subscriptions on this topic.
|
UnaryCallable<com.google.pubsub.v1.ListTopicSubscriptionsRequest,com.google.pubsub.v1.ListTopicSubscriptionsResponse> |
listTopicSubscriptionsCallable()
Lists the names of the subscriptions on this topic.
|
UnaryCallable<com.google.pubsub.v1.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)
Sets the access control policy on the specified resource.
|
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> |
setIamPolicyCallable()
Sets the access control policy on the specified resource.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(String resource,
List<String> permissions)
Returns permissions that a caller has on the specified resource.
|
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on the specified resource.
|
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that a caller has on the specified resource.
|
com.google.pubsub.v1.Topic |
updateTopic(com.google.pubsub.v1.UpdateTopicRequest request)
Updates an existing topic.
|
UnaryCallable<com.google.pubsub.v1.UpdateTopicRequest,com.google.pubsub.v1.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
IOException
public 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 com.google.pubsub.v1.Topic createTopic(com.google.pubsub.v1.ProjectTopicName name)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name);
}
name
- 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"`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Topic createTopic(String name)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.createTopic(name.toString());
}
name
- 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"`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Topic createTopic(com.google.pubsub.v1.Topic request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.Topic,com.google.pubsub.v1.Topic> createTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName name = ProjectTopicName.of("[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 com.google.pubsub.v1.Topic updateTopic(com.google.pubsub.v1.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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.UpdateTopicRequest,com.google.pubsub.v1.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 com.google.pubsub.v1.Topic getTopic(com.google.pubsub.v1.ProjectTopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
topic
- The name of the topic to get. Format is `projects/{project}/topics/{topic}`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Topic getTopic(String topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic.toString());
}
topic
- The name of the topic to get. Format is `projects/{project}/topics/{topic}`.ApiException
- if the remote call failspublic final com.google.pubsub.v1.Topic getTopic(com.google.pubsub.v1.GetTopicRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.GetTopicRequest,com.google.pubsub.v1.Topic> getTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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(com.google.pubsub.v1.ProjectName project)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
for (Topic element : topicAdminClient.listTopics(project).iterateAll()) {
// doThingsWith(element);
}
}
project
- The name of the project in which to list topics. Format is
`projects/{project-id}`.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
- The name of the project in which to list topics. Format is
`projects/{project-id}`.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicsPagedResponse listTopics(com.google.pubsub.v1.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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.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 UnaryCallable<com.google.pubsub.v1.ListTopicsRequest,com.google.pubsub.v1.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(com.google.pubsub.v1.ProjectTopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
topic
- The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(String topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
for (ProjectSubscriptionName element : topicAdminClient.listTopicSubscriptions(topic.toString()).iterateAllAsProjectSubscriptionName()) {
// doThingsWith(element);
}
}
topic
- The name of the topic that subscriptions are attached to. Format is
`projects/{project}/topics/{topic}`.ApiException
- if the remote call failspublic final TopicAdminClient.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(com.google.pubsub.v1.ListTopicSubscriptionsRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.ListTopicSubscriptionsRequest,TopicAdminClient.ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsPagedCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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 UnaryCallable<com.google.pubsub.v1.ListTopicSubscriptionsRequest,com.google.pubsub.v1.ListTopicSubscriptionsResponse> listTopicSubscriptionsCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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(com.google.pubsub.v1.ProjectTopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
topic
- Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.ApiException
- if the remote call failspublic final void deleteTopic(String topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic.toString());
}
topic
- Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.ApiException
- if the remote call failspublic final void deleteTopic(com.google.pubsub.v1.DeleteTopicRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.pubsub.v1.DeleteTopicRequest,Empty> deleteTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectTopicName topic = ProjectTopicName.of("[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(String resource, com.google.iam.v1.Policy policy)
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. `resource` is
usually specified as a path. For example, a Project resource is specified as
`projects/{project}`.policy
- REQUIRED: The complete policy to be applied to the `resource`. The size of the
policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
Platform services (such as Projects) might reject them.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.setPolicy(policy)
.build();
Policy response = topicAdminClient.setIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.setPolicy(policy)
.build();
ApiFuture<Policy> future = topicAdminClient.setIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(String resource)
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. `resource` is
usually specified as a path. For example, a Project resource is specified as
`projects/{project}`.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.build();
Policy response = topicAdminClient.getIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.build();
ApiFuture<Policy> future = topicAdminClient.getIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
Sample code:
try (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.
`resource` is usually specified as a path. For example, a Project resource is specified as
`projects/{project}`.permissions
- The set of permissions to check for the `resource`. Permissions with
wildcards (such as '*' or 'storage.*') are not allowed. For more information see
[IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).ApiException
- if the remote call failspublic final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(formattedResource)
.addAllPermissions(permissions)
.build();
TestIamPermissionsResponse response = topicAdminClient.testIamPermissions(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(formattedResource)
.addAllPermissions(permissions)
.build();
ApiFuture<TestIamPermissionsResponse> future = topicAdminClient.testIamPermissionsCallable().futureCall(request);
// Do something
TestIamPermissionsResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.