Search in sources :

Example 6 with KeySharedPolicy

use of org.apache.pulsar.client.api.KeySharedPolicy in project flink-mirror by flink-ci.

the class PulsarPartitionSplitReaderBase method createPulsarConsumer.

/**
 * Create a specified {@link Consumer} by the given topic partition.
 */
protected Consumer<byte[]> createPulsarConsumer(TopicPartition partition) {
    ConsumerBuilder<byte[]> consumerBuilder = createConsumerBuilder(pulsarClient, Schema.BYTES, sourceConfiguration);
    consumerBuilder.topic(partition.getFullTopicName());
    // Add KeySharedPolicy for Key_Shared subscription.
    if (sourceConfiguration.getSubscriptionType() == SubscriptionType.Key_Shared) {
        KeySharedPolicy policy = KeySharedPolicy.stickyHashRange().ranges(partition.getPulsarRange());
        consumerBuilder.keySharedPolicy(policy);
    }
    // Create the consumer configuration by using common utils.
    return sneakyClient(consumerBuilder::subscribe);
}
Also used : KeySharedPolicy(org.apache.pulsar.client.api.KeySharedPolicy)

Aggregations

KeySharedPolicy (org.apache.pulsar.client.api.KeySharedPolicy)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 TimeUnit (java.util.concurrent.TimeUnit)3 Pattern (java.util.regex.Pattern)3 Collectors (java.util.stream.Collectors)3 AccessLevel (lombok.AccessLevel)3 Getter (lombok.Getter)3 NonNull (lombok.NonNull)3 StringUtils (org.apache.commons.lang3.StringUtils)3 BatchReceivePolicy (org.apache.pulsar.client.api.BatchReceivePolicy)3 Consumer (org.apache.pulsar.client.api.Consumer)3 ConsumerBuilder (org.apache.pulsar.client.api.ConsumerBuilder)3 ConsumerCryptoFailureAction (org.apache.pulsar.client.api.ConsumerCryptoFailureAction)3 ConsumerEventListener (org.apache.pulsar.client.api.ConsumerEventListener)3