Search in sources :

Example 1 with AdminClient

use of com.google.cloud.pubsublite.AdminClient in project beam by apache.

the class ReadWriteIT method createTopic.

private TopicPath createTopic(ProjectId id) throws Exception {
    TopicPath toReturn = TopicPath.newBuilder().setProject(id).setLocation(ZONE).setName(TopicName.of(randomName())).build();
    Topic.Builder topic = Topic.newBuilder().setName(toReturn.toString());
    topic.getPartitionConfigBuilder().setCount(2).setCapacity(Capacity.newBuilder().setPublishMibPerSec(4).setSubscribeMibPerSec(4));
    topic.getRetentionConfigBuilder().setPerPartitionBytes(30 * (1L << 30));
    cleanupActions.addLast(() -> {
        try (AdminClient client = newAdminClient()) {
            client.deleteTopic(toReturn).get();
        } catch (Throwable t) {
            LOG.error("Failed to clean up topic.", t);
        }
    });
    try (AdminClient client = newAdminClient()) {
        client.createTopic(topic.build()).get();
    }
    return toReturn;
}
Also used : TopicPath(com.google.cloud.pubsublite.TopicPath) Topic(com.google.cloud.pubsublite.proto.Topic) AdminClient(com.google.cloud.pubsublite.AdminClient)

Example 2 with AdminClient

use of com.google.cloud.pubsublite.AdminClient in project beam by apache.

the class ReadWriteIT method createSubscription.

private SubscriptionPath createSubscription(TopicPath topic) throws Exception {
    SubscriptionPath toReturn = SubscriptionPath.newBuilder().setProject(topic.project()).setLocation(ZONE).setName(SubscriptionName.of(randomName())).build();
    Subscription.Builder subscription = Subscription.newBuilder().setName(toReturn.toString());
    subscription.getDeliveryConfigBuilder().setDeliveryRequirement(DeliveryRequirement.DELIVER_IMMEDIATELY);
    subscription.setTopic(topic.toString());
    cleanupActions.addLast(() -> {
        try (AdminClient client = newAdminClient()) {
            client.deleteSubscription(toReturn).get();
        } catch (Throwable t) {
            LOG.error("Failed to clean up subscription.", t);
        }
    });
    try (AdminClient client = newAdminClient()) {
        client.createSubscription(subscription.build(), BacklogLocation.BEGINNING).get();
    }
    return toReturn;
}
Also used : SubscriptionPath(com.google.cloud.pubsublite.SubscriptionPath) Subscription(com.google.cloud.pubsublite.proto.Subscription) AdminClient(com.google.cloud.pubsublite.AdminClient)

Aggregations

AdminClient (com.google.cloud.pubsublite.AdminClient)2 SubscriptionPath (com.google.cloud.pubsublite.SubscriptionPath)1 TopicPath (com.google.cloud.pubsublite.TopicPath)1 Subscription (com.google.cloud.pubsublite.proto.Subscription)1 Topic (com.google.cloud.pubsublite.proto.Topic)1