com.google.api.services.pubsub.model.ListTopicsResponse Java Examples
The following examples show how to use
com.google.api.services.pubsub.model.ListTopicsResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TopicMethods.java From cloud-pubsub-samples-java with Apache License 2.0 | 6 votes |
/** * Lists existing topics in the project. * * @param client Cloud Pub/Sub client. * @param args Command line arguments. * @throws IOException when Cloud Pub/Sub API calls fail. */ public static void listTopics(final Pubsub client, final String[] args) throws IOException { String nextPageToken = null; boolean hasTopics = false; Pubsub.Projects.Topics.List listMethod = client.projects().topics().list("projects/" + args[0]); do { if (nextPageToken != null) { listMethod.setPageToken(nextPageToken); } ListTopicsResponse response = listMethod.execute(); if (!response.isEmpty()) { for (Topic topic : response.getTopics()) { hasTopics = true; System.out.println(topic.getName()); } } nextPageToken = response.getNextPageToken(); } while (nextPageToken != null); if (!hasTopics) { System.out.println(String.format( "There are no topics in the project '%s'.", args[0])); } }
Example #2
Source File: PubsubJsonClientTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void listTopics() throws Exception { ListTopicsResponse expectedResponse1 = new ListTopicsResponse(); expectedResponse1.setTopics(Collections.singletonList(buildTopic(1))); expectedResponse1.setNextPageToken("AVgJH3Z7aHxiDBs"); ListTopicsResponse expectedResponse2 = new ListTopicsResponse(); expectedResponse2.setTopics(Collections.singletonList(buildTopic(2))); Topics.List request = mockPubsub.projects().topics().list(PROJECT.getPath()); when((Object) (request.execute())).thenReturn(expectedResponse1, expectedResponse2); List<TopicPath> topicPaths = client.listTopics(PROJECT); assertEquals(2, topicPaths.size()); }