Pil0tXia commented on code in PR #4438:
URL: https://github.com/apache/eventmesh/pull/4438#discussion_r1321039439


##########
eventmesh-storage-plugin/eventmesh-storage-kafka/src/main/java/org/apache/eventmesh/storage/kafka/admin/KafkaAdmin.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.storage.kafka.admin;
+
+import static 
org.apache.eventmesh.storage.kafka.common.EventMeshConstants.DEFAULT_TIMEOUT_IN_SECONDS;
+
+import org.apache.eventmesh.api.admin.AbstractAdmin;
+import org.apache.eventmesh.api.admin.TopicProperties;
+import org.apache.eventmesh.common.config.ConfigService;
+import org.apache.eventmesh.storage.kafka.config.ClientConfiguration;
+
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.DescribeTopicsResult;
+import org.apache.kafka.clients.admin.ListOffsetsResult.ListOffsetsResultInfo;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.admin.OffsetSpec;
+import org.apache.kafka.clients.admin.TopicDescription;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.TopicPartitionInfo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class KafkaAdmin extends AbstractAdmin {
+
+    // properties for kafka admin client
+    private static final Properties kafkaProps = new Properties();
+
+    // properties for topic management
+    private static final Map<String, Integer> topicProps = new HashMap<>();
+
+    public KafkaAdmin() {
+        super(new AtomicBoolean(false));
+
+        ConfigService configService = ConfigService.getInstance();
+        ClientConfiguration clientConfiguration = 
configService.buildConfigInstance(ClientConfiguration.class);
+
+        kafkaProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, 
clientConfiguration.getNamesrvAddr());
+        topicProps.put("partitionNum", clientConfiguration.getPartitions());
+        topicProps.put("replicationFactorNum", (int) 
clientConfiguration.getReplicationFactors());
+    }
+
+    @Override
+    public List<TopicProperties> getTopic() {
+        try (Admin client = Admin.create(kafkaProps)) {

Review Comment:
   try-with-resource is the recommended usage of Kafka Admin API on the Kafka 
official documentation:
   
   
https://github.com/apache/kafka/blob/b72d92919f71f7360cd712741c0470759fc10239/clients/src/main/java/org/apache/kafka/clients/admin/Admin.java#L75-L93
   
   You may check out 
`org.apache.eventmesh.storage.rocketmq.admin.RocketMQAdmin#createMQAdminExt` to 
find a similar treatment.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to