When you use ApsaraMQ for Kafka, message accumulation may occur in a group. This topic describes how to determine whether message accumulation is normal and how to handle abnormal message accumulation.
Consumption process on a client
To understand whether message accumulation exists, you must understand how messages are consumed on a client. The following figure describes the consumption process.
Determine whether message accumulation is normal
If message accumulation occurs in a group, perform the following steps to determine whether the message accumulation is normal:
Log on to the ApsaraMQ for Kafka console.
How to handle abnormal message accumulation
After you confirm that abnormal message accumulation exists based on the preceding operations, you can print the message consumption duration or check the execution of the thread based on the stack information. You can use the following methods to increase the message consumption rate to prevent abnormal message accumulation:
Increase the number of consumers. You can add consumers in a process and make sure that each consumer corresponds to one thread. Alternatively, you can deploy multiple consumer processes. If the number of consumers exceeds the number of partitions, the consumption rate cannot be increased. Otherwise, specific consumers become idle.
Increase the number of consumption threads. For more information, see the "Increase consumption rate" section of the Best practices for consumers topic.
You can run the jstack command to query the stack information about Java threads.
If messages are accumulated and the consumer status is abnormal in the ApsaraMQ for Kafka console, rebalances may have occurred. During rebalances, messages are not consumed. In this case, messages are accumulated because a large number of clients connect to or disconnect from ApsaraMQ for Kafka. For more information, see Why do rebalances frequently occur on my consumer client?
References
For information about jstack, see jstack - Stack Trace.
For information about other frequently asked questions (FAQ), see FAQ.