Search in sources :

Example 1 with ConsumerConfigurationData

use of org.apache.pulsar.client.impl.conf.ConsumerConfigurationData in project incubator-pulsar by apache.

the class PulsarClientImpl method patternTopicSubscribeAsync.

private <T> CompletableFuture<Consumer<T>> patternTopicSubscribeAsync(ConsumerConfigurationData<T> conf, Schema<T> schema) {
    String regex = conf.getTopicsPattern().pattern();
    TopicName destination = TopicName.get(regex);
    NamespaceName namespaceName = destination.getNamespaceObject();
    CompletableFuture<Consumer<T>> consumerSubscribedFuture = new CompletableFuture<>();
    lookup.getTopicsUnderNamespace(namespaceName).thenAccept(topics -> {
        if (log.isDebugEnabled()) {
            log.debug("Get topics under namespace {}, topics.size: {}", namespaceName.toString(), topics.size());
            topics.forEach(topicName -> log.debug("Get topics under namespace {}, topic: {}", namespaceName.toString(), topicName));
        }
        List<String> topicsList = topicsPatternFilter(topics, conf.getTopicsPattern());
        conf.getTopicNames().addAll(topicsList);
        ConsumerBase<T> consumer = new PatternTopicsConsumerImpl<>(conf.getTopicsPattern(), PulsarClientImpl.this, conf, externalExecutorProvider.getExecutor(), consumerSubscribedFuture, schema);
        synchronized (consumers) {
            consumers.put(consumer, Boolean.TRUE);
        }
    }).exceptionally(ex -> {
        log.warn("[{}] Failed to get topics under namespace", namespaceName);
        consumerSubscribedFuture.completeExceptionally(ex);
        return null;
    });
    return consumerSubscribedFuture;
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) TopicName(org.apache.pulsar.common.naming.TopicName) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ReaderConfigurationData(org.apache.pulsar.client.impl.conf.ReaderConfigurationData) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Producer(org.apache.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) 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) ProducerBuilder(org.apache.pulsar.client.api.ProducerBuilder) Lists(com.google.common.collect.Lists) ExecutorProvider(org.apache.pulsar.client.util.ExecutorProvider) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) ThreadFactory(java.util.concurrent.ThreadFactory) PulsarClient(org.apache.pulsar.client.api.PulsarClient) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) PulsarClientException(org.apache.pulsar.client.api.PulsarClientException) ExecutorService(java.util.concurrent.ExecutorService) EventLoopGroup(io.netty.channel.EventLoopGroup) IdentityHashMap(java.util.IdentityHashMap) EventLoopUtil(org.apache.pulsar.common.util.netty.EventLoopUtil) Logger(org.slf4j.Logger) ReaderConfiguration(org.apache.pulsar.client.api.ReaderConfiguration) Reader(org.apache.pulsar.client.api.Reader) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) ProducerConfiguration(org.apache.pulsar.client.api.ProducerConfiguration) 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) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) MessageId(org.apache.pulsar.client.api.MessageId) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ClientConfigurationData(org.apache.pulsar.client.impl.conf.ClientConfigurationData) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) ReaderBuilder(org.apache.pulsar.client.api.ReaderBuilder) Pattern(java.util.regex.Pattern) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) CompletableFuture(java.util.concurrent.CompletableFuture) Consumer(org.apache.pulsar.client.api.Consumer) List(java.util.List) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 2 with ConsumerConfigurationData

use of org.apache.pulsar.client.impl.conf.ConsumerConfigurationData in project incubator-pulsar by apache.

the class ConsumerConfigurationTest method testJsonIgnore.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testJsonIgnore() throws Exception {
    ConsumerConfigurationData<?> conf = new ConsumerConfigurationData<>();
    conf.setConsumerEventListener(new ConsumerEventListener() {

        @Override
        public void becameActive(Consumer<?> consumer, int partitionId) {
        }

        @Override
        public void becameInactive(Consumer<?> consumer, int partitionId) {
        }
    });
    conf.setMessageListener((MessageListener) (consumer, msg) -> {
    });
    conf.setCryptoKeyReader(mock(CryptoKeyReader.class));
    ObjectMapper m = new ObjectMapper();
    m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    ObjectWriter w = m.writerWithDefaultPrettyPrinter();
    String confAsString = w.writeValueAsString(conf);
    log.info("conf : {}", confAsString);
    assertFalse(confAsString.contains("messageListener"));
    assertFalse(confAsString.contains("consumerEventListener"));
    assertFalse(confAsString.contains("cryptoKeyReader"));
}
Also used : Logger(org.slf4j.Logger) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) LoggerFactory(org.slf4j.LoggerFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Assert.assertFalse(org.testng.Assert.assertFalse) Mockito.mock(org.mockito.Mockito.mock) ConsumerConfigurationData(org.apache.pulsar.client.impl.conf.ConsumerConfigurationData) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

ConsumerConfigurationData (org.apache.pulsar.client.impl.conf.ConsumerConfigurationData)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Timer (io.netty.util.Timer)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1