Search in sources :

Example 1 with KeySharedMode

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

the class KeySharedSubscriptionTest method testSelectorChangedAfterAllConsumerDisconnected.

@Test(dataProvider = "topicDomain")
public void testSelectorChangedAfterAllConsumerDisconnected(String topicDomain) throws PulsarClientException, ExecutionException, InterruptedException {
    final String topicName = TopicName.get(topicDomain, "public", "default", "testSelectorChangedAfterAllConsumerDisconnected" + UUID.randomUUID()).toString();
    final String subName = "my-sub";
    Consumer<byte[]> consumer1 = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).consumerName("first-consumer").subscriptionType(SubscriptionType.Key_Shared).keySharedPolicy(KeySharedPolicy.autoSplitHashRange()).cryptoKeyReader(new EncKeyReader()).subscribe();
    CompletableFuture<Optional<Topic>> future = pulsar.getBrokerService().getTopicIfExists(topicName);
    assertTrue(future.isDone());
    assertTrue(future.get().isPresent());
    Topic topic = future.get().get();
    KeySharedMode keySharedMode = getKeySharedModeOfSubscription(topic, subName);
    assertNotNull(keySharedMode);
    assertEquals(keySharedMode, KeySharedMode.AUTO_SPLIT);
    consumer1.close();
    consumer1 = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).consumerName("second-consumer").subscriptionType(SubscriptionType.Key_Shared).keySharedPolicy(KeySharedPolicy.stickyHashRange().ranges(Range.of(0, 65535))).cryptoKeyReader(new EncKeyReader()).subscribe();
    future = pulsar.getBrokerService().getTopicIfExists(topicName);
    assertTrue(future.isDone());
    assertTrue(future.get().isPresent());
    topic = future.get().get();
    keySharedMode = getKeySharedModeOfSubscription(topic, subName);
    assertNotNull(keySharedMode);
    assertEquals(keySharedMode, KeySharedMode.STICKY);
    consumer1.close();
}
Also used : KeySharedMode(org.apache.pulsar.common.api.proto.KeySharedMode) Optional(java.util.Optional) Topic(org.apache.pulsar.broker.service.Topic) Test(org.testng.annotations.Test)

Example 2 with KeySharedMode

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

the class NonPersistentSubscription method getStats.

public NonPersistentSubscriptionStatsImpl getStats() {
    NonPersistentSubscriptionStatsImpl subStats = new NonPersistentSubscriptionStatsImpl();
    subStats.bytesOutCounter = bytesOutFromRemovedConsumers.longValue();
    subStats.msgOutCounter = msgOutFromRemovedConsumer.longValue();
    NonPersistentDispatcher dispatcher = this.dispatcher;
    if (dispatcher != null) {
        dispatcher.getConsumers().forEach(consumer -> {
            ConsumerStatsImpl consumerStats = consumer.getStats();
            subStats.consumers.add(consumerStats);
            subStats.msgRateOut += consumerStats.msgRateOut;
            subStats.msgThroughputOut += consumerStats.msgThroughputOut;
            subStats.bytesOutCounter += consumerStats.bytesOutCounter;
            subStats.msgOutCounter += consumerStats.msgOutCounter;
            subStats.msgRateRedeliver += consumerStats.msgRateRedeliver;
        });
    }
    subStats.type = getTypeString();
    subStats.msgDropRate = dispatcher.getMessageDropRate().getValueRate();
    KeySharedMode keySharedMode = this.keySharedMode;
    if (getType() == SubType.Key_Shared && keySharedMode != null) {
        subStats.keySharedMode = keySharedMode.toString();
    }
    return subStats;
}
Also used : KeySharedMode(org.apache.pulsar.common.api.proto.KeySharedMode) ConsumerStatsImpl(org.apache.pulsar.common.policies.data.stats.ConsumerStatsImpl) NonPersistentSubscriptionStatsImpl(org.apache.pulsar.common.policies.data.stats.NonPersistentSubscriptionStatsImpl)

Aggregations

KeySharedMode (org.apache.pulsar.common.api.proto.KeySharedMode)2 Optional (java.util.Optional)1 Topic (org.apache.pulsar.broker.service.Topic)1 ConsumerStatsImpl (org.apache.pulsar.common.policies.data.stats.ConsumerStatsImpl)1 NonPersistentSubscriptionStatsImpl (org.apache.pulsar.common.policies.data.stats.NonPersistentSubscriptionStatsImpl)1 Test (org.testng.annotations.Test)1