public void unsubscribe() {
        acquireAndEnsureOpen();
        try {
            fetcher.clearBufferedDataForUnassignedPartitions(Collections.emptySet());
            if (this.coordinator != null) {
                this.coordinator.onLeavePrepare();
                this.coordinator.maybeLeaveGroup("the consumer unsubscribed from all topics");
            }
            this.subscriptions.unsubscribe();
            log.info("Unsubscribed all topics or patterns and assigned partitions");
        } finally {
            release();
        }
    }
Internal helper method for {@link #subscribe(Pattern)} and
{@link #subscribe(Pattern, ConsumerRebalanceListener)}
<p>
Subscribe to all topics matching specified pattern to get dynamically assigned partitions.
The pattern matching will be done periodically against all topics existing at the time of check.
This can be controlled through the {@code metadata.max.age.ms} configuration: by lowering
the max metadata age, the consumer will refresh metadata more often and check for matching topics.
<p>
See {@link #subscribe(Collection, ConsumerRebalanceListener)} for details on the
use of the {@link ConsumerRebalanceListener}. Generally rebalances are triggered when there
is a change to the topics matching the provided pattern and when consumer group membership changes.
Group rebalances only take place during an active call to {@link #poll(Duration)}.

@param pattern Pattern to subscribe to
@param listener {@link Optional} listener instance to get notifications on partition assignment/revocation
                for the subscribed topics
@throws IllegalArgumentException If pattern or listener is null
@throws IllegalStateException If {@code subscribe()} is called previously with topics, or assign is called
                              previously (without a subsequent call to {@link #unsubscribe()}), or if not
                              configured at-least one partition assignment strategy
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ClassicKafkaConsumer.java