pl.allegro.tech.hermes.consumers.subscription.id.ZookeeperSubscriptionIdProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-consumers Show documentation
Show all versions of hermes-consumers Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.consumers.subscription.id;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.data.Stat;
import pl.allegro.tech.hermes.api.SubscriptionName;
import pl.allegro.tech.hermes.common.exception.InternalProcessingException;
import pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperPaths;
import java.util.Optional;
public class ZookeeperSubscriptionIdProvider implements SubscriptionIdProvider {
private final CuratorFramework curatorFramework;
private final ZookeeperPaths zookeeperPaths;
public ZookeeperSubscriptionIdProvider(CuratorFramework curatorFramework, ZookeeperPaths zookeeperPaths) {
this.curatorFramework = curatorFramework;
this.zookeeperPaths = zookeeperPaths;
}
@Override
public SubscriptionId getSubscriptionId(SubscriptionName name) {
return Optional.ofNullable(getZnodeStat(name))
.map(Stat::getCzxid)
.map(czxid -> SubscriptionId.from(name, czxid))
.orElseThrow(() -> new IllegalStateException(
String.format("Cannot get czxid of subscription %s as it doesn't exist", name.getQualifiedName())));
}
private Stat getZnodeStat(SubscriptionName name) {
String path = zookeeperPaths.subscriptionPath(name.getTopicName(), name.getName());
try {
return curatorFramework.checkExists().forPath(path);
} catch (Exception e) {
throw new InternalProcessingException(String.format("Could not check existence of subscription %s node",
name.getQualifiedName()), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy