BewareMyPower edited a comment on issue #13965:
URL: https://github.com/apache/pulsar/issues/13965#issuecomment-1022132557


   Yeah, here is a screenshot of my Java consumer application. (It should have 
received 3000 messages in total, and sometimes it works well.)
   
   
![image](https://user-images.githubusercontent.com/18204803/151159254-d4fa05fc-e8b5-46da-9185-9d136c0b659b.png)
   
   The code is
   
   ```java
       private static int receive(Consumer<byte[]> consumer) throws 
PulsarClientException {
           int n = 0;
           while (true) {
               final Message<byte[]> msg = consumer.receive(2, 
TimeUnit.SECONDS);
               if (msg == null) {
                   break;
               }
               n++;
               System.out.println("Received " + new String(msg.getValue())
                       + " from " + msg.getMessageId() +  ", key: " + 
msg.getKey());
           }
           return n;
       }
   
       public static void main(String[] args) throws PulsarClientException {
           final PulsarClient client = 
PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
           final ConsumerBuilder<byte[]> builder = client.newConsumer()
                   .topicsPattern(".*KeySharedConsumerTest-multi-topics.*")
                   
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
                   .subscriptionType(SubscriptionType.Key_Shared)
                   .subscriptionName("my-sub-1");
           final Consumer<byte[]> consumer1 = builder.clone().subscribe();
           final Consumer<byte[]> consumer2 = builder.clone().subscribe();
           final Consumer<byte[]> consumer3 = builder.clone().subscribe();
           int n1 = receive(consumer1);
           int n2 = receive(consumer2);
           int n3 = receive(consumer3);
           System.out.println("n1: " + n1 + ", n2: " + n2 + ", n3: " + n3 + ", 
total: " + (n1 + n2 + n3));
           client.close();
       }
   ```
   
   But I cannot reproduce it with Java UT easily at the moment.


-- 
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