guozhangwang commented on code in PR #12035: URL: https://github.com/apache/kafka/pull/12035#discussion_r857908050
########## streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java: ########## @@ -1498,6 +1516,37 @@ public synchronized boolean close(final Duration timeout) throws IllegalArgument return close(timeoutMs); } + /** + * Shutdown this {@code KafkaStreams} by signaling all the threads to stop, and then wait up to the timeout for the + * threads to join. + * @param options contains timeout to specify how long to wait for the threads to shutdown, and a flag leaveGroup to + * trigger consumer leave call + * @return {@code true} if all threads were successfully stopped—{@code false} if the timeout was reached + * before all threads stopped + * Note that this method must not be called in the {@link StateListener#onChange(KafkaStreams.State, KafkaStreams.State)} callback of {@link StateListener}. + * @throws IllegalArgumentException if {@code timeout} can't be represented as {@code long milliseconds} + */ + public synchronized boolean close(final CloseOptions options) throws IllegalArgumentException { + final String msgPrefix = prepareMillisCheckFailMsgPrefix(options.timeout, "timeout"); + final long timeoutMs = validateMillisecondDuration(options.timeout, msgPrefix); + if (timeoutMs < 0) { + throw new IllegalArgumentException("Timeout can't be negative."); + } + + if (options.leaveGroup) { + log.debug("Sending leave group trigger to removing instance from consumer group"); + //removing instance from consumer group + adminClient.removeMembersFromConsumerGroup( + applicationConfigs.getString(StreamsConfig.APPLICATION_ID_CONFIG), + new RemoveMembersFromConsumerGroupOptions() + ); Review Comment: Hi @dajac thanks for your comments. 1) I think your call out for not specifying the member id in `RemoveMembersFromConsumerGroupOptions` is right (and sorry I missed that in my pass). This can be retrieved from `KafkaConsumer#groupMetadata`. 2) Regarding the "leave-group" behavior, the thing is that with static member today we would disable sending the leave-group request (this is an internal config of Consumer, named as `LEAVE_GROUP_ON_CLOSE_CONFIG`, used by Streams). And since it's a config, we cannot re-enable it on the fly --- and that's why I once talked to you about having `KafkaConsumer#close` to expose a similar mechanism to indicate whether or not send leave-group as well --- so the only way left to enforcing the member to be removed immediately is via the admin client. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org