@Generated(value="by GAPIC v0.0.5") @BetaApi 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.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 | 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.TopicName name)
Creates the given topic with the given name.
|
com.google.api.gax.rpc.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.TopicName topic)
Deletes the topic with the given name.
|
com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.DeleteTopicRequest,com.google.protobuf.Empty> |
deleteTopicCallable()
Deletes the topic with the given name.
|
com.google.iam.v1.Policy |
getIamPolicy(String resource)
Gets the access control policy for a resource.
|
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() |
com.google.pubsub.v1.Topic |
getTopic(com.google.pubsub.v1.TopicName topic)
Gets the configuration of a topic.
|
com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.GetTopicRequest,com.google.pubsub.v1.Topic> |
getTopicCallable()
Gets the configuration of a topic.
|
boolean |
isShutdown() |
boolean |
isTerminated() |
PagedResponseWrappers.ListTopicsPagedResponse |
listTopics(com.google.pubsub.v1.ListTopicsRequest request)
Lists matching topics.
|
PagedResponseWrappers.ListTopicsPagedResponse |
listTopics(com.google.pubsub.v1.ProjectName project)
Lists matching topics.
|
com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.ListTopicsRequest,com.google.pubsub.v1.ListTopicsResponse> |
listTopicsCallable()
Lists matching topics.
|
com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.ListTopicsRequest,PagedResponseWrappers.ListTopicsPagedResponse> |
listTopicsPagedCallable()
Lists matching topics.
|
PagedResponseWrappers.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(com.google.pubsub.v1.ListTopicSubscriptionsRequest request)
Lists the name of the subscriptions for this topic.
|
PagedResponseWrappers.ListTopicSubscriptionsPagedResponse |
listTopicSubscriptions(com.google.pubsub.v1.TopicName topic)
Lists the name of the subscriptions for this topic.
|
com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.ListTopicSubscriptionsRequest,com.google.pubsub.v1.ListTopicSubscriptionsResponse> |
listTopicSubscriptionsCallable()
Lists the name of the subscriptions for this topic.
|
com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.ListTopicSubscriptionsRequest,PagedResponseWrappers.ListTopicSubscriptionsPagedResponse> |
listTopicSubscriptionsPagedCallable()
Lists the name of the subscriptions for 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.
|
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)
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.
|
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.
|
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 com.google.pubsub.v1.Topic createTopic(com.google.pubsub.v1.TopicName name)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.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"`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.Topic,com.google.pubsub.v1.Topic> createTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName name = TopicName.of("[PROJECT]", "[TOPIC]");
Topic request = Topic.newBuilder()
.setNameWithTopicName(name)
.build();
ApiFuture<Topic> future = topicAdminClient.createTopicCallable().futureCall(request);
// Do something
Topic response = future.get();
}
public final com.google.pubsub.v1.Topic getTopic(com.google.pubsub.v1.TopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
Topic response = topicAdminClient.getTopic(topic);
}
topic - 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 com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.GetTopicRequest,com.google.pubsub.v1.Topic> getTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
GetTopicRequest request = GetTopicRequest.newBuilder()
.setTopicWithTopicName(topic)
.build();
ApiFuture<Topic> future = topicAdminClient.getTopicCallable().futureCall(request);
// Do something
Topic response = future.get();
}
public final PagedResponseWrappers.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 cloud project that topics belong to. Format is
`projects/{project}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final PagedResponseWrappers.ListTopicsPagedResponse listTopics(com.google.pubsub.v1.ListTopicsRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListTopicsRequest request = ListTopicsRequest.newBuilder()
.setProjectWithProjectName(project)
.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<com.google.pubsub.v1.ListTopicsRequest,PagedResponseWrappers.ListTopicsPagedResponse> listTopicsPagedCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ProjectName project = ProjectName.of("[PROJECT]");
ListTopicsRequest request = ListTopicsRequest.newBuilder()
.setProjectWithProjectName(project)
.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<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()
.setProjectWithProjectName(project)
.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 PagedResponseWrappers.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(com.google.pubsub.v1.TopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
for (SubscriptionName element : topicAdminClient.listTopicSubscriptions(topic).iterateAllAsSubscriptionName()) {
// doThingsWith(element);
}
}
topic - 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 PagedResponseWrappers.ListTopicSubscriptionsPagedResponse listTopicSubscriptions(com.google.pubsub.v1.ListTopicSubscriptionsRequest request)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
.setTopicWithTopicName(topic)
.build();
for (SubscriptionName element : topicAdminClient.listTopicSubscriptions(request).iterateAllAsSubscriptionName()) {
// 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<com.google.pubsub.v1.ListTopicSubscriptionsRequest,PagedResponseWrappers.ListTopicSubscriptionsPagedResponse> listTopicSubscriptionsPagedCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
.setTopicWithTopicName(topic)
.build();
ApiFuture<ListTopicSubscriptionsPagedResponse> future = topicAdminClient.listTopicSubscriptionsPagedCallable().futureCall(request);
// Do something
for (SubscriptionName element : future.get().iterateAllAsSubscriptionName()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.ListTopicSubscriptionsRequest,com.google.pubsub.v1.ListTopicSubscriptionsResponse> listTopicSubscriptionsCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest.newBuilder()
.setTopicWithTopicName(topic)
.build();
while (true) {
ListTopicSubscriptionsResponse response = topicAdminClient.listTopicSubscriptionsCallable().call(request);
for (SubscriptionName element : response.getSubscriptionsListAsSubscriptionNameList()) {
// 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.TopicName topic)
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
topicAdminClient.deleteTopic(topic);
}
topic - Name of the topic to delete. Format is `projects/{project}/topics/{topic}`.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.pubsub.v1.DeleteTopicRequest,com.google.protobuf.Empty> deleteTopicCallable()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topic = TopicName.of("[PROJECT]", "[TOPIC]");
DeleteTopicRequest request = DeleteTopicRequest.newBuilder()
.setTopicWithTopicName(topic)
.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 = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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.com.google.api.gax.rpc.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 = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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.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()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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 = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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}`.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()) {
String formattedResource = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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 = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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).com.google.api.gax.rpc.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 = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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.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()
Sample code:
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
String formattedResource = TopicName.of("[PROJECT]", "[TOPIC]").toString();
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()
throws Exception
close in interface AutoCloseableExceptionpublic 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 © 2017 Google. All rights reserved.