Search in sources :

Example 1 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse 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());
}
Also used : ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse)

Example 2 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse in project kafka-rest by confluentinc.

the class TopicsResourceTest method listTopics_existingCluster_returnsTopics.

@Test
public void listTopics_existingCluster_returnsTopics() {
    expect(topicManager.listTopics(CLUSTER_ID, false)).andReturn(completedFuture(Arrays.asList(TOPIC_1, TOPIC_2, TOPIC_3)));
    replay(topicManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    topicsResource.listTopics(response, CLUSTER_ID, false);
    ListTopicsResponse expected = ListTopicsResponse.create(TopicDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics").build()).setData(Arrays.asList(newTopicData("topic-1", true, 3, 3), newTopicData("topic-2", true, 3, 3), newTopicData("topic-3", false, 3, 3))).build());
    assertEquals(expected, response.getValue());
}
Also used : FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListTopicsResponse(io.confluent.kafkarest.entities.v3.ListTopicsResponse) Test(org.junit.jupiter.api.Test)

Example 3 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse in project java-pubsub by googleapis.

the class TopicAdminClientTest method listTopicsTest.

@Test
public void listTopicsTest() throws Exception {
    Topic responsesElement = Topic.newBuilder().build();
    ListTopicsResponse expectedResponse = ListTopicsResponse.newBuilder().setNextPageToken("").addAllTopics(Arrays.asList(responsesElement)).build();
    mockPublisher.addResponse(expectedResponse);
    ProjectName project = ProjectName.of("[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<AbstractMessage> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTopicsRequest actualRequest = ((ListTopicsRequest) actualRequests.get(0));
    Assert.assertEquals(project.toString(), actualRequest.getProject());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListTopicsPagedResponse(com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.pubsub.v1.ProjectName) ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) Topic(com.google.pubsub.v1.Topic) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse) Test(org.junit.Test)

Example 4 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse in project beam by apache.

the class PubsubGrpcClient method listTopics.

@Override
public List<TopicPath> listTopics(ProjectPath project) throws IOException {
    ListTopicsRequest.Builder request = ListTopicsRequest.newBuilder().setProject(project.getPath()).setPageSize(LIST_BATCH_SIZE);
    ListTopicsResponse response = publisherStub().listTopics(request.build());
    if (response.getTopicsCount() == 0) {
        return ImmutableList.of();
    }
    List<TopicPath> topics = new ArrayList<>(response.getTopicsCount());
    while (true) {
        for (Topic topic : response.getTopicsList()) {
            topics.add(topicPathFromPath(topic.getName()));
        }
        if (response.getNextPageToken().isEmpty()) {
            break;
        }
        request.setPageToken(response.getNextPageToken());
        response = publisherStub().listTopics(request.build());
    }
    return topics;
}
Also used : ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) ArrayList(java.util.ArrayList) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse) Topic(com.google.pubsub.v1.Topic)

Example 5 with ListTopicsResponse

use of io.confluent.kafkarest.entities.v3.ListTopicsResponse 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());
}
Also used : ListTopicsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse) ProjectName(com.google.pubsub.v1.ProjectName) ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) ByteString(com.google.protobuf.ByteString) Topic(com.google.pubsub.v1.Topic) ListTopicsResponse(com.google.pubsub.v1.ListTopicsResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

ListTopicsRequest (com.google.pubsub.v1.ListTopicsRequest)5 ListTopicsResponse (com.google.pubsub.v1.ListTopicsResponse)5 Topic (com.google.pubsub.v1.Topic)4 Test (org.junit.Test)3 ListTopicsPagedResponse (com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 ProjectName (com.google.pubsub.v1.ProjectName)2 ListTopicsResponse (io.confluent.kafkarest.entities.v3.ListTopicsResponse)2 Test (org.junit.jupiter.api.Test)2 ListTopicsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 CreateTopicResponse (io.confluent.kafkarest.entities.v3.CreateTopicResponse)1 GetTopicConfigResponse (io.confluent.kafkarest.entities.v3.GetTopicConfigResponse)1 GetTopicResponse (io.confluent.kafkarest.entities.v3.GetTopicResponse)1 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1