Search in sources :

Example 41 with Topic

use of com.google.pubsub.v1.Topic 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 42 with Topic

use of com.google.pubsub.v1.Topic in project beam by apache.

the class PubsubGrpcClient method createTopic.

@Override
public void createTopic(TopicPath topic) throws IOException {
    Topic request = Topic.newBuilder().setName(topic.getPath()).build();
    // ignore Topic result.
    publisherStub().createTopic(request);
}
Also used : Topic(com.google.pubsub.v1.Topic)

Aggregations

TopicName (com.google.pubsub.v1.TopicName)26 Test (org.junit.Test)22 Topic (com.google.pubsub.v1.Topic)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)8 ByteString (com.google.protobuf.ByteString)7 PubsubMessage (com.google.pubsub.v1.PubsubMessage)7 ApiException (com.google.api.gax.grpc.ApiException)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 Subscription (com.google.pubsub.v1.Subscription)5 ArrayList (java.util.ArrayList)5 ListTopicsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse)3 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)3 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)3 DeleteTopicRequest (com.google.pubsub.v1.DeleteTopicRequest)3 ListTopicsRequest (com.google.pubsub.v1.ListTopicsRequest)3 PublishRequest (com.google.pubsub.v1.PublishRequest)3 PublishResponse (com.google.pubsub.v1.PublishResponse)3 AckReplyConsumer (com.google.cloud.pubsub.spi.v1.AckReplyConsumer)2