You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Chia-Ping Tsai (Jira)" <ji...@apache.org> on 2024/04/19 21:08:00 UTC

[jira] [Created] (KAFKA-16589) Consider removing `ClusterInstance#createAdminClient` since callers are not sure whether they need to call close

Chia-Ping Tsai created KAFKA-16589:
--------------------------------------

             Summary: Consider removing `ClusterInstance#createAdminClient` since callers are not sure whether they need to call close
                 Key: KAFKA-16589
                 URL: https://issues.apache.org/jira/browse/KAFKA-16589
             Project: Kafka
          Issue Type: Improvement
            Reporter: Chia-Ping Tsai
            Assignee: Chia-Ping Tsai


Sometimes we close the admin created by `createAdminClient`, and sometimes we don't. That is not a true problem since the `ClusterInstance` will call `close` when stopping.

However, that cause a lot of inconsistent code, and in fact it does not save much time since creating a Admin is not a hard work. We can get `bootstrapServers` and `bootstrapControllers` from `ClusterInstance` easily.

 
{code:java}
// before
try (Admin admin = cluster.createAdminClient()) { }

// after v0
try (Admin admin = Admin.create(Collections.singletonMap(
        CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, cluster.bootstrapServers()))) {}

{code}
Personally, the `after` version is not verbose, but we can have alternatives: `Map<String, Object> clientConfigs`.

 
{code:java}
// after v1
try (Admin admin = Admin.create(cluster.clientConfigs())) {}{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)