@Override
    public void unsubscribe() {
        acquireAndEnsureOpen();
        try {
            fetchBuffer.retainAll(Collections.emptySet());
            Timer timer = time.timer(Long.MAX_VALUE);
            UnsubscribeEvent unsubscribeEvent = new UnsubscribeEvent(calculateDeadlineMs(timer));
            applicationEventHandler.add(unsubscribeEvent);
            log.info("Unsubscribing all topics or patterns and assigned partitions {}",
                    subscriptions.assignedPartitions());

            try {
                processBackgroundEvents(unsubscribeEvent.future(), timer);
                log.info("Unsubscribed all topics or patterns and assigned partitions");
            } catch (TimeoutException e) {
                log.error("Failed while waiting for the unsubscribe event to complete");
            }
            resetGroupMetadata();
        } catch (Exception e) {
            log.error("Unsubscribe failed", e);
            throw e;
        } finally {
            release();
        }
    }
<p>

This function evaluates the regex that the consumer subscribed to
against the list of topic names from metadata, and updates
the list of topics in subscription state accordingly

@param cluster Cluster from which we get the topics
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java