Search in sources :

Example 1 with Mode

use of org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode in project incubator-pulsar by apache.

the class PulsarClientImpl method patternTopicSubscribeAsync.

private <T> CompletableFuture<Consumer<T>> patternTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema, ConsumerInterceptors<T> interceptors) {
    String regex = conf.getTopicsPattern().pattern();
    Mode subscriptionMode = convertRegexSubscriptionMode(conf.getRegexSubscriptionMode());
    TopicName destination = TopicName.get(regex);
    NamespaceName namespaceName = destination.getNamespaceObject();
    CompletableFuture<Consumer<T>> consumerSubscribedFuture = new CompletableFuture<>();
    lookup.getTopicsUnderNamespace(namespaceName, subscriptionMode, regex, null).thenAccept(getTopicsResult -> {
        if (log.isDebugEnabled()) {
            log.debug("Get topics under namespace {}, topics.size: {}," + " topicsHash: {}, changed: {}, filtered: {}", namespaceName, getTopicsResult.getTopics().size(), getTopicsResult.getTopicsHash(), getTopicsResult.isChanged(), getTopicsResult.isFiltered());
            getTopicsResult.getTopics().forEach(topicName -> log.debug("Get topics under namespace {}, topic: {}", namespaceName, topicName));
        }
        List<String> topicsList = getTopicsResult.getTopics();
        if (!getTopicsResult.isFiltered()) {
            topicsList = TopicList.filterTopics(getTopicsResult.getTopics(), conf.getTopicsPattern());
        }
        conf.getTopicNames().addAll(topicsList);
        ConsumerBase<T> consumer = new PatternMultiTopicsConsumerImpl<>(conf.getTopicsPattern(), getTopicsResult.getTopicsHash(), PulsarClientImpl.this, conf, externalExecutorProvider, consumerSubscribedFuture, schema, subscriptionMode, interceptors);
        consumers.add(consumer);
    }).exceptionally(ex -> {
        log.warn("[{}] Failed to get topics under namespace", namespaceName);
        consumerSubscribedFuture.completeExceptionally(ex);
        return null;
    });
    return consumerSubscribedFuture;
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ReaderConfigurationData(org.apache.pulsar.client.impl.conf.ReaderConfigurationData) Producer(org.apache.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) Duration(java.time.Duration) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) ThreadFactory(java.util.concurrent.ThreadFactory) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) EventLoopUtil(org.apache.pulsar.common.util.netty.EventLoopUtil) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) AuthenticationFactory(org.apache.pulsar.client.api.AuthenticationFactory) MultiVersionSchemaInfoProvider(org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider) TransactionBuilderImpl(org.apache.pulsar.client.impl.transaction.TransactionBuilderImpl) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) Mode(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode) CacheLoader(com.google.common.cache.CacheLoader) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) TopicList(org.apache.pulsar.common.topics.TopicList) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Builder(lombok.Builder) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) Optional(java.util.Optional) KeyValueSchema(org.apache.pulsar.client.api.schema.KeyValueSchema) CacheBuilder(com.google.common.cache.CacheBuilder) SchemaInfo(org.apache.pulsar.common.schema.SchemaInfo) TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) RegexSubscriptionMode(org.apache.pulsar.client.api.RegexSubscriptionMode) CompletableFuture(java.util.concurrent.CompletableFuture) ConsumerBuilder(org.apache.pulsar.client.api.ConsumerBuilder) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionCoordinatorClientImpl(org.apache.pulsar.client.impl.transaction.TransactionCoordinatorClientImpl) ArrayList(java.util.ArrayList) ProducerBuilder(org.apache.pulsar.client.api.ProducerBuilder) TransactionBuilder(org.apache.pulsar.client.api.transaction.TransactionBuilder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AutoProduceBytesSchema(org.apache.pulsar.client.impl.schema.AutoProduceBytesSchema) PulsarClient(org.apache.pulsar.client.api.PulsarClient) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) ExecutorService(java.util.concurrent.ExecutorService) SchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider) EventLoopGroup(io.netty.channel.EventLoopGroup) Logger(org.slf4j.Logger) Reader(org.apache.pulsar.client.api.Reader) IOException(java.io.IOException) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) Schema(org.apache.pulsar.client.api.Schema) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) AutoConsumeSchema(org.apache.pulsar.client.impl.schema.AutoConsumeSchema) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Authentication(org.apache.pulsar.client.api.Authentication) Clock(java.time.Clock) ReaderBuilder(org.apache.pulsar.client.api.ReaderBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TableViewBuilder(org.apache.pulsar.client.api.TableViewBuilder) Collections(java.util.Collections) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(org.apache.pulsar.client.api.Consumer) Mode(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode) RegexSubscriptionMode(org.apache.pulsar.client.api.RegexSubscriptionMode) List(java.util.List) TopicList(org.apache.pulsar.common.topics.TopicList) ArrayList(java.util.ArrayList) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 2 with Mode

use of org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode in project pulsar by yahoo.

the class PulsarClientImpl method patternTopicSubscribeAsync.

private <T> CompletableFuture<Consumer<T>> patternTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema, ConsumerInterceptors<T> interceptors) {
    String regex = conf.getTopicsPattern().pattern();
    Mode subscriptionMode = convertRegexSubscriptionMode(conf.getRegexSubscriptionMode());
    TopicName destination = TopicName.get(regex);
    NamespaceName namespaceName = destination.getNamespaceObject();
    CompletableFuture<Consumer<T>> consumerSubscribedFuture = new CompletableFuture<>();
    lookup.getTopicsUnderNamespace(namespaceName, subscriptionMode, regex, null).thenAccept(getTopicsResult -> {
        if (log.isDebugEnabled()) {
            log.debug("Get topics under namespace {}, topics.size: {}," + " topicsHash: {}, changed: {}, filtered: {}", namespaceName, getTopicsResult.getTopics().size(), getTopicsResult.getTopicsHash(), getTopicsResult.isChanged(), getTopicsResult.isFiltered());
            getTopicsResult.getTopics().forEach(topicName -> log.debug("Get topics under namespace {}, topic: {}", namespaceName, topicName));
        }
        List<String> topicsList = getTopicsResult.getTopics();
        if (!getTopicsResult.isFiltered()) {
            topicsList = TopicList.filterTopics(getTopicsResult.getTopics(), conf.getTopicsPattern());
        }
        conf.getTopicNames().addAll(topicsList);
        ConsumerBase<T> consumer = new PatternMultiTopicsConsumerImpl<>(conf.getTopicsPattern(), getTopicsResult.getTopicsHash(), PulsarClientImpl.this, conf, externalExecutorProvider, consumerSubscribedFuture, schema, subscriptionMode, interceptors);
        consumers.add(consumer);
    }).exceptionally(ex -> {
        log.warn("[{}] Failed to get topics under namespace", namespaceName);
        consumerSubscribedFuture.completeExceptionally(ex);
        return null;
    });
    return consumerSubscribedFuture;
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ReaderConfigurationData(org.apache.pulsar.client.impl.conf.ReaderConfigurationData) Producer(org.apache.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) Duration(java.time.Duration) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) ThreadFactory(java.util.concurrent.ThreadFactory) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) EventLoopUtil(org.apache.pulsar.common.util.netty.EventLoopUtil) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) AuthenticationFactory(org.apache.pulsar.client.api.AuthenticationFactory) MultiVersionSchemaInfoProvider(org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider) TransactionBuilderImpl(org.apache.pulsar.client.impl.transaction.TransactionBuilderImpl) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) Mode(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode) CacheLoader(com.google.common.cache.CacheLoader) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) TopicList(org.apache.pulsar.common.topics.TopicList) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Builder(lombok.Builder) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) Optional(java.util.Optional) KeyValueSchema(org.apache.pulsar.client.api.schema.KeyValueSchema) CacheBuilder(com.google.common.cache.CacheBuilder) SchemaInfo(org.apache.pulsar.common.schema.SchemaInfo) TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) RegexSubscriptionMode(org.apache.pulsar.client.api.RegexSubscriptionMode) CompletableFuture(java.util.concurrent.CompletableFuture) ConsumerBuilder(org.apache.pulsar.client.api.ConsumerBuilder) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionCoordinatorClientImpl(org.apache.pulsar.client.impl.transaction.TransactionCoordinatorClientImpl) ArrayList(java.util.ArrayList) ProducerBuilder(org.apache.pulsar.client.api.ProducerBuilder) TransactionBuilder(org.apache.pulsar.client.api.transaction.TransactionBuilder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AutoProduceBytesSchema(org.apache.pulsar.client.impl.schema.AutoProduceBytesSchema) PulsarClient(org.apache.pulsar.client.api.PulsarClient) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) ExecutorService(java.util.concurrent.ExecutorService) SchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider) EventLoopGroup(io.netty.channel.EventLoopGroup) Logger(org.slf4j.Logger) Reader(org.apache.pulsar.client.api.Reader) IOException(java.io.IOException) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) Schema(org.apache.pulsar.client.api.Schema) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) AutoConsumeSchema(org.apache.pulsar.client.impl.schema.AutoConsumeSchema) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Authentication(org.apache.pulsar.client.api.Authentication) Clock(java.time.Clock) ReaderBuilder(org.apache.pulsar.client.api.ReaderBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TableViewBuilder(org.apache.pulsar.client.api.TableViewBuilder) Collections(java.util.Collections) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(org.apache.pulsar.client.api.Consumer) Mode(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode) RegexSubscriptionMode(org.apache.pulsar.client.api.RegexSubscriptionMode) List(java.util.List) TopicList(org.apache.pulsar.common.topics.TopicList) ArrayList(java.util.ArrayList) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 3 with Mode

use of org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode in project pulsar by apache.

the class PulsarClientImpl method patternTopicSubscribeAsync.

private <T> CompletableFuture<Consumer<T>> patternTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema, ConsumerInterceptors<T> interceptors) {
    String regex = conf.getTopicsPattern().pattern();
    Mode subscriptionMode = convertRegexSubscriptionMode(conf.getRegexSubscriptionMode());
    TopicName destination = TopicName.get(regex);
    NamespaceName namespaceName = destination.getNamespaceObject();
    CompletableFuture<Consumer<T>> consumerSubscribedFuture = new CompletableFuture<>();
    lookup.getTopicsUnderNamespace(namespaceName, subscriptionMode).thenAccept(topics -> {
        if (log.isDebugEnabled()) {
            log.debug("Get topics under namespace {}, topics.size: {}", namespaceName, topics.size());
            topics.forEach(topicName -> log.debug("Get topics under namespace {}, topic: {}", namespaceName, topicName));
        }
        List<String> topicsList = topicsPatternFilter(topics, conf.getTopicsPattern());
        conf.getTopicNames().addAll(topicsList);
        ConsumerBase<T> consumer = new PatternMultiTopicsConsumerImpl<>(conf.getTopicsPattern(), PulsarClientImpl.this, conf, externalExecutorProvider, consumerSubscribedFuture, schema, subscriptionMode, interceptors);
        consumers.add(consumer);
    }).exceptionally(ex -> {
        log.warn("[{}] Failed to get topics under namespace", namespaceName);
        consumerSubscribedFuture.completeExceptionally(ex);
        return null;
    });
    return consumerSubscribedFuture;
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ReaderConfigurationData(org.apache.pulsar.client.impl.conf.ReaderConfigurationData) Producer(org.apache.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) Duration(java.time.Duration) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) ThreadFactory(java.util.concurrent.ThreadFactory) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) EventLoopUtil(org.apache.pulsar.common.util.netty.EventLoopUtil) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) AuthenticationFactory(org.apache.pulsar.client.api.AuthenticationFactory) MultiVersionSchemaInfoProvider(org.apache.pulsar.client.impl.schema.generic.MultiVersionSchemaInfoProvider) TransactionBuilderImpl(org.apache.pulsar.client.impl.transaction.TransactionBuilderImpl) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Mode(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode) CacheLoader(com.google.common.cache.CacheLoader) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Builder(lombok.Builder) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) Optional(java.util.Optional) KeyValueSchema(org.apache.pulsar.client.api.schema.KeyValueSchema) CacheBuilder(com.google.common.cache.CacheBuilder) Pattern(java.util.regex.Pattern) SchemaInfo(org.apache.pulsar.common.schema.SchemaInfo) TopicName(org.apache.pulsar.common.naming.TopicName) Getter(lombok.Getter) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) RegexSubscriptionMode(org.apache.pulsar.client.api.RegexSubscriptionMode) CompletableFuture(java.util.concurrent.CompletableFuture) ConsumerBuilder(org.apache.pulsar.client.api.ConsumerBuilder) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionCoordinatorClientImpl(org.apache.pulsar.client.impl.transaction.TransactionCoordinatorClientImpl) ArrayList(java.util.ArrayList) ProducerBuilder(org.apache.pulsar.client.api.ProducerBuilder) TransactionBuilder(org.apache.pulsar.client.api.transaction.TransactionBuilder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AutoProduceBytesSchema(org.apache.pulsar.client.impl.schema.AutoProduceBytesSchema) PulsarClient(org.apache.pulsar.client.api.PulsarClient) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) ExecutorService(java.util.concurrent.ExecutorService) SchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider) EventLoopGroup(io.netty.channel.EventLoopGroup) Logger(org.slf4j.Logger) Reader(org.apache.pulsar.client.api.Reader) IOException(java.io.IOException) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ProducerConfigurationData(org.apache.pulsar.client.impl.conf.ProducerConfigurationData) Schema(org.apache.pulsar.client.api.Schema) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) AutoConsumeSchema(org.apache.pulsar.client.impl.schema.AutoConsumeSchema) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Authentication(org.apache.pulsar.client.api.Authentication) Clock(java.time.Clock) ReaderBuilder(org.apache.pulsar.client.api.ReaderBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TableViewBuilder(org.apache.pulsar.client.api.TableViewBuilder) Collections(java.util.Collections) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(org.apache.pulsar.client.api.Consumer) Mode(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace.Mode) RegexSubscriptionMode(org.apache.pulsar.client.api.RegexSubscriptionMode) List(java.util.List) ArrayList(java.util.ArrayList) TopicName(org.apache.pulsar.common.naming.TopicName)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 CacheBuilder (com.google.common.cache.CacheBuilder)3 CacheLoader (com.google.common.cache.CacheLoader)3 LoadingCache (com.google.common.cache.LoadingCache)3 EventLoopGroup (io.netty.channel.EventLoopGroup)3 HashedWheelTimer (io.netty.util.HashedWheelTimer)3 Timer (io.netty.util.Timer)3 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)3 IOException (java.io.IOException)3 Clock (java.time.Clock)3 Duration (java.time.Duration)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3