use of com.google.pubsub.v1.ListTopicsRequest in project grpc-java by grpc.
the class GoogleAuthClient method getTopics.
/**
* Get topics (max 10) for our project ID: the topic list is logged to the logger.
*
* @param projectID the GCP project ID to get the pubsub topics for. This is a string like
* "projects/balmy-cirrus-225307" where "balmy-cirrus-225307" is
* the project ID for the project you created.
*/
public void getTopics(String projectID) {
logger.log(Level.INFO, "Will try to get topics for project {0} ...", projectID);
ListTopicsRequest request = ListTopicsRequest.newBuilder().setPageSize(// get max 10 topics
10).setProject(// for our projectID
projectID).build();
ListTopicsResponse response;
try {
response = blockingStub.listTopics(request);
} catch (StatusRuntimeException e) {
logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
return;
}
logger.log(Level.INFO, "Topics list:\n {0}", response.getTopicsList());
}
use of com.google.pubsub.v1.ListTopicsRequest in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientSnippets method listTopics.
/** Example of listing topics. */
public ListTopicsPagedResponse listTopics() throws Exception {
// [START pubsub_list_topics]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest listTopicsRequest = ListTopicsRequest.newBuilder().setProjectWithProjectName(ProjectName.create(projectId)).build();
ListTopicsPagedResponse response = topicAdminClient.listTopics(listTopicsRequest);
Iterable<Topic> topics = response.iterateAll();
for (Topic topic : topics) {
// do something with the topic
}
return response;
}
// [END pubsub_list_topics]
}
use of com.google.pubsub.v1.ListTopicsRequest in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method listTopicsTest.
@Test
@SuppressWarnings("all")
public void listTopicsTest() {
String nextPageToken = "";
Topic topicsElement = Topic.newBuilder().build();
List<Topic> topics = Arrays.asList(topicsElement);
ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder().setNextPageToken(nextPageToken).addAllTopics(topics).build();
mockPublisher.addResponse(expectedResponse);
ProjectName project = ProjectName.create("[PROJECT]");
ListTopicsPagedResponse pagedListResponse = client.listTopics(project);
List<Topic> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTopicsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTopicsRequest actualRequest = (ListTopicsRequest) actualRequests.get(0);
Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
Aggregations