crossoverJie opened a new issue, #18799:
URL: https://github.com/apache/pulsar/issues/18799

   ### Motivation
   
   Wait for the consumer's job to finish before closing the consumer, and fix 
#8308 
   
   ### Goal
   
   In some scenarios, we need the consumer to finish executing the task before 
closing it, otherwise, the message will be consumed again when the consumer 
restarts.
   
   ### API Changes
   
   `ConsumerBuilder` will add a new parameter.
   
   ```java
   Consumer<String> consumer = pulsarClient.newConsumer(Schema.STRING)
           .topics(listTopic)
           .subscriptionName(subscriptionName)
           .subscriptionType(SubscriptionType.Shared)
           .closeWaitForJob(CloseWaitForJobPolicy.builder()
                   .closeWaitForJob(true)
                   .timeout(5, TimeUnit.SECONDS)
                   .build())
           .subscribe();
   ```
   
   ### Implementation
   
   New wait notification mechanism when closing consumer.
   
   The main steps are as follows:
   - Record the number of messages received.
        - Related functions: `receive()/batchReceive()` etc.
   - When processing a message, the number of messages is subtracted by one, 
and a notification is sent when the number of messages equals 0.
        - Related functions: `acknowledge()/negativeAcknowledge()`
   - Blocks the thread when the consumer is closed until it is woken up.
        - Related function: `close()`.
   
    The prerequisite here is that the user uses this API.
   
   ### Alternatives
   
   _No response_
   
   ### Anything else?
   
   PR: https://github.com/apache/pulsar/pull/18795


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