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();
}
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;
}
Aggregations