CodingOX opened a new issue, #718:
URL: https://github.com/apache/rocketmq-clients/issues/718

   ### Before Creating the Bug Report
   
   - [X] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq-clients/discussions).
   
   - [X] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq-clients/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq-clients/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [X] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Programming Language of the Client
   
   Java
   
   ### Runtime Platform Environment
   
   
   - Broker Ubuntu 20
   - Client Win 10
   
   ### RocketMQ Version of the Client/Server
   
   - Broker apache/rocketmq:5.2.0
   - rocketmq-client-java:5.0.6
   
   
   ### Run or Compiler Version
   
   - Zulu JDK Java 17
   - Broker Ubuntu 20
   - Client Win 10
   
   ### Describe the Bug
   
   When using SimpleConsumer in RocketMQ client, there is a noticeable delay 
when consuming the last few messages produced by the producer. The JDK version 
is Java 17, and the client version is rocketmq-client-java 5.0.6.
   
   ### Steps to Reproduce
   
   
   When using `SimpleConsumer` in RocketMQ client, there is a noticeable delay 
when consuming the last few messages produced by the producer. The JDK version 
is Java 17, and the client version is rocketmq-client-java 5.0.6.
   
   Here is the core producer code written in Kotlin:
   ```kotlin
   fun main() {
       val log: Logger = LoggerFactory.getLogger("benchmark-producer")
       val provider = ClientServiceProvider.loadService()
       val snowflakeGenerator = SnowflakeGenerator()
   
       val endpoints = "rmq5-broker-1.middle:8081;rmq5-broker-2.middle:8081"
       val clientConfiguration = ClientConfiguration.newBuilder()
           .setEndpoints(endpoints)
           .build()
   
       val topic = "BenchmarkTopic"
       val tag = "benchmark-1"
   
       val producer = provider.newProducerBuilder()
           .setTopics(topic)
           .setClientConfiguration(clientConfiguration)
           .build()
   
       try {
           repeat(20) {
               val id = snowflakeGenerator.next()
               val message = provider
                   .newMessageBuilder()
                   .setTag(tag)
                   .setKeys(id.toString())
                   .setTopic(topic)
                   .setBody("${System.currentTimeMillis()}".toByteArray())
                   .build()
   
               producer.send(message)
               log.info("Send message: $id - ${message.tag}")
           }
       } catch (ex: Exception) {
           log.error("Send message error", ex)
       }
   }
   ```
   
   Consumer code:
   ```kotlin
   fun main() {
       val log: Logger = LoggerFactory.getLogger("benchmark-consumer")
       val provider = ClientServiceProvider.loadService()
   
       val endpoints = "rmq5-broker-1.middle:8081;rmq5-broker-2.middle:8081"
       val clientConfiguration = ClientConfiguration.newBuilder()
           .setEndpoints(endpoints)
           .build()
   
       val tag = "benchmark-1"
       val filterExpression = FilterExpression(tag, FilterExpressionType.TAG)
   
       val consumerGroup = "BenchmarkConsumerGroup"
       val topic = "BenchmarkTopic"
   
       val simpleConsumer = provider
           .newSimpleConsumerBuilder()
           .setClientConfiguration(clientConfiguration)
           .setConsumerGroup(consumerGroup)
           .setAwaitDuration(Duration.ofMillis(2200))
           .setSubscriptionExpressions(mapOf(topic to filterExpression))
           .build()
   
       val invisibleDuration = Duration.ofSeconds(10)
   
       while (true) {
           simpleConsumer.receive(10, invisibleDuration).forEach {
               val start = 
Convert.toLong(StandardCharsets.UTF_8.decode(it.body), 0)
               simpleConsumer.ack(it)
               log.info("Consumed ${it.messageId} - ${it.tag}- Time taken: 
${System.currentTimeMillis() - start}")
           }
       }
   }
   ```
   
   Below is a snippet of consumer logs displaying the issue:
   ```
   17:35:01.650 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000000 - Optional[benchmark-1]- Time Taken: 140
   17:35:01.662 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000003 - Optional[benchmark-1]- Time Taken: 77
   17:35:01.665 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000002 - Optional[benchmark-1]- Time Taken: 84
   17:35:01.668 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000007 - Optional[benchmark-1]- Time Taken: 68
   17:35:01.671 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000008 - Optional[benchmark-1]- Time Taken: 67
   17:35:01.674 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B4061825450000000B - Optional[benchmark-1]- Time Taken: 60
   17:35:01.677 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000006 - Optional[benchmark-1]- Time Taken: 81
   17:35:01.679 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000001 - Optional[benchmark-1]- Time Taken: 102
   17:35:01.681 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000009 - Optional[benchmark-1]- Time Taken: 74
   17:35:01.684 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B4061825450000000E - Optional[benchmark-1]- Time Taken: 60
   17:35:01.686 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000004 - Optional[benchmark-1]- Time Taken: 97
   17:35:01.693 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B4061825450000000F - Optional[benchmark-1]- Time Taken: 65
   17:35:01.695 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000005 - Optional[benchmark-1]- Time Taken: 102
   17:35:01.697 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B4061825450000000C - Optional[benchmark-1]- Time Taken: 80
   17:35:01.699 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B4061825450000000D - Optional[benchmark-1]- Time Taken: 78
   17:35:01.702 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B4061825450000000A - Optional[benchmark-1]- Time Taken: 92
   17:35:06.665 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000011 - Optional[benchmark-1]- Time Taken: 5031
   17:35:06.667 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000010 - Optional[benchmark-1]- Time Taken: 5036
   17:35:06.669 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000012 - Optional[benchmark-1]- Time Taken: 5032
   17:35:06.670 [main] INFO benchmark-consumer -- Consumed  
0100FFC3968162A9B40618254500000013 - Optional[benchmark-1]- Time Taken: 5030
   ```
   
   Please refer to the provided code snippets and consumer logs for further 
investigation into the significant delay issue encountered while consuming the 
last few messages produced by the SimpleConsumer in RocketMQ client.
   
   ### What Did You Expect to See?
   
   Consume the message as soon as possible, no delay.
   
   ### What Did You See Instead?
   
   There is excessive delay when consuming the last 4(or n) messages.
   
   ### Additional Context
   
   _No response_


-- 
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: commits-unsubscr...@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to