tombentley commented on code in PR #11781: URL: https://github.com/apache/kafka/pull/11781#discussion_r897812219
########## connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java: ########## @@ -1327,30 +1334,39 @@ public WorkerTask doBuild(Task task, connectorClientConfigOverridePolicy, kafkaClusterId); KafkaProducer<byte[], byte[]> producer = new KafkaProducer<>(producerProps); - TopicAdmin topicAdmin; + // Prepare to create a topic admin if the task requires one, but do not actually create an instance + // until/unless one is needed + final AtomicReference<TopicAdmin> topicAdmin = new AtomicReference<>(); + final Supplier<TopicAdmin> topicAdminCreator = () -> topicAdmin.updateAndGet(existingAdmin -> { + if (existingAdmin != null) { + return existingAdmin; + } + Map<String, Object> adminOverrides = adminConfigs(id.connector(), "connector-adminclient-" + id, config, + sourceConfig, connectorClass, connectorClientConfigOverridePolicy, kafkaClusterId, ConnectorType.SOURCE); + Admin adminClient = Admin.create(adminOverrides); + return new TopicAdmin(adminOverrides.get(BOOTSTRAP_SERVERS_CONFIG), adminClient); + }); + Map<String, TopicCreationGroup> topicCreationGroups; if (config.topicCreationEnable() && sourceConfig.usesTopicCreation()) { topicCreationGroups = TopicCreationGroup.configuredGroups(sourceConfig); // Create a topic admin that the task can use for topic creation - Map<String, Object> adminOverrides = adminConfigs(id.connector(), "connector-adminclient-" + id, config, - sourceConfig, connectorClass, connectorClientConfigOverridePolicy, kafkaClusterId, ConnectorType.SOURCE); - topicAdmin = new TopicAdmin(adminOverrides); + topicAdminCreator.get(); Review Comment: Thanks! When you have time it would be great if you could rebase that PR. -- 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