Why resume the consumer before invoke the listeners? #1819
-
Hi there, i am looking for the help to understand the logic in the following code block, protected void pollAndInvoke() {
...
pauseConsumerIfNecessary();
...
resumeConsumerIfNeccessary();
...
invokeIfHaveRecords(records);
} what is the reason/benefit to resume the consumer before invoke the listeners? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If the consumer is paused (at the application's request), the poll will return no records, so the listener won't be invoked, so it doesn't matter where the resume is done. An application might pause the container (and hence the consumer before the next poll), if it is not ready to receive new records, but it wants to remain part of the consumer group and not cause a rebalance. The listener CANNOT "take a long time" - it must be able to handle the records returned by the poll within the configured pause/resume is simply a mechanism to remain part of the group while not actively receiving any records, but we must continue to poll. |
Beta Was this translation helpful? Give feedback.
If the consumer is paused (at the application's request), the poll will return no records, so the listener won't be invoked, so it doesn't matter where the resume is done.
An application might pause the container (and hence the consumer before the next poll), if it is not ready to receive new records, but it wants to remain part of the consumer group and not cause a rebalance.
The listener CANNOT "take a long time" - it must be able to handle the records returned by the poll within the configured
max.poll.interval.ms
. Otherwise, the broker will force a rebalance.pause/resume is simply a mechanism to remain part of the group while not actively receiving any records, but we must continue t…