Search in sources :

Example 1 with SubscriptionNotInitializedException

use of org.zalando.nakadi.service.subscription.zk.SubscriptionNotInitializedException in project nakadi by zalando.

the class CursorsService method getSubscriptionCursors.

public List<SubscriptionCursorWithoutToken> getSubscriptionCursors(final String subscriptionId) throws NakadiException, ServiceTemporarilyUnavailableException {
    final Subscription subscription = subscriptionRepository.getSubscription(subscriptionId);
    final ZkSubscriptionClient zkSubscriptionClient = zkSubscriptionFactory.createClient(subscription, "subscription." + subscriptionId + ".get_cursors");
    final ImmutableList.Builder<SubscriptionCursorWithoutToken> cursorsListBuilder = ImmutableList.builder();
    Partition[] partitions;
    try {
        partitions = zkSubscriptionClient.getTopology().getPartitions();
    } catch (final SubscriptionNotInitializedException ex) {
        partitions = new Partition[] {};
    }
    final Map<EventTypePartition, SubscriptionCursorWithoutToken> positions = zkSubscriptionClient.getOffsets(Stream.of(partitions).map(Partition::getKey).collect(Collectors.toList()));
    for (final Partition p : partitions) {
        cursorsListBuilder.add(positions.get(p.getKey()));
    }
    return cursorsListBuilder.build();
}
Also used : SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) Partition(org.zalando.nakadi.service.subscription.model.Partition) ZkSubscriptionClient(org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient) ImmutableList(com.google.common.collect.ImmutableList) SubscriptionNotInitializedException(org.zalando.nakadi.service.subscription.zk.SubscriptionNotInitializedException) Subscription(org.zalando.nakadi.domain.Subscription) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)1 Subscription (org.zalando.nakadi.domain.Subscription)1 Partition (org.zalando.nakadi.service.subscription.model.Partition)1 SubscriptionNotInitializedException (org.zalando.nakadi.service.subscription.zk.SubscriptionNotInitializedException)1 ZkSubscriptionClient (org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient)1 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)1