megfigura commented on issue #10495:
URL: https://github.com/apache/pulsar/issues/10495#issuecomment-915269613


   Thanks @MarvinCai,
   
   The new behavior in 2.8.1 is much better. At least as far as I can tell, it 
still requires a type cast, but that's not so bad. This code is working:
   ```java
   String topicName = "non-persistent://public/default/my_topic";
   TopicStats topicStats = admin.topics().getStats(topicName);
   SubscriptionStats subStats = stats.getSubscriptions().get("drop_test");
   double dropRate = 0.0;
   if (subStats instanceof NonPersistentSubscriptionStats)
   {
       NonPersistentSubscriptionStats npSubStats = 
(NonPersistentSubscriptionStats)subStats;
       dropRate = npSubStats.getMsgDropRate();
   }
   ```
   
   This beats my previous work-around in 2.7.1 (which no longer worked in 
2.8.0):
   ```java
   String topicName = "non-persistent://public/default/my_topic";
   TopicStats topicStats;
   if (topicName.startsWith("non-persistent")
   {
       topicStats = admin.nonPersistentTopics().getStats(topicName);
   }
   else
   {
       topicStats = admin.topics().getStats(topicName);
   }
   
   double dropRate = 0.0;
   if (topicStats instanceof NonPersistentTopicStats)
   {
       NonPersistentTopicStats npTopicStats = 
(NonPersistentTopicStats)topicStats;
       dropRate = 
npTopicStats.getSubscriptions().get("drop_test").getMsgDropRate();
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to