t3link opened a new issue #10523:
URL: https://github.com/apache/pulsar/issues/10523


   I tested `pulsar 2.7.1 docker` on my local machine. Also java client version 
is `2.7.1`
   `1` producer with `4` consumer in a single app container configured below.
   The producer produced messages orderly with message key ranged from `test-0` 
to `test-9`
   ```java
   private static final AtomicLong KEY_GENERATOR = new AtomicLong();
   
   private static String randomKey() {
       var idx = KEY_GENERATOR.getAndIncrement() % 10;
       return "test-" + idx;
   }
   
   @Bean
   public Producer<String> producer(PulsarClient client) throws 
PulsarClientException {
       return client.newProducer(Schema.STRING)
               .topic("topic-test")
               .sendTimeout(10, TimeUnit.SECONDS)
               .create();
   }
   
   @Bean
   public List<Consumer<String>> consumer(PulsarClient client) throws 
PulsarClientException {
       var consumers = new ArrayList<Consumer<String>>(4);
       for (var i = 0; i < 4; i++) {
           var consumer = client.newConsumer(Schema.STRING)
                   .topic("topic-test")
                   .subscriptionName("sub-test")
                   .subscriptionType(SubscriptionType.Key_Shared)
                   .subscribe();
           consumers.add(consumer);
       }
       return consumers;
   }
   ```
   When I first run only one app container. The consumer statistics output 
seems not evenly distributed.
   ```
   {
       "consumer-thread-2":[
           "test-2",
           "test-1",
           "test-0",
           "test-6",
           "test-4"
       ],
       "consumer-thread-3":[
           "test-9"
       ],
       "consumer-thread-0":[
           "test-3"
       ],
       "consumer-thread-1":[
           "test-8",
           "test-7",
           "test-5"
       ]
   }
   ```
   
   Then 30 seconds later, I started a new app container. Now there are two 
containers running at the same time.
   
   The previous contiainer consumer statistics output changed!
   ```
   {
       "consumer-thread-2":[
           "test-4"
       ],
       "consumer-thread-3":[
           "test-9"
       ],
       "consumer-thread-0":[
           "test-3"
       ],
       "consumer-thread-1":[
           "test-8",
           "test-7"
       ]
   }
   ```
   
   And the newer container consumer statistics output like this.
   ```
   {
       "consumer-thread-0":[
           "test-2",
           "test-1",
           "test-0",
           "test-6"
       ],
       "consumer-thread-1":[
           "test-5"
       ]
   }
   ```
   
   **Part of consumer in the newer container is even not distributed to consume 
any message.**
   
   Is there some best practice advices for Key_Shared subscription? I think 
this is a comman situation in production environment. The app containers may be 
deployed dynamically and caused subscription change. 


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

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


Reply via email to