hit-lacus commented on a change in pull request #1298:
URL: https://github.com/apache/kylin/pull/1298#discussion_r453416200



##########
File path: 
core-common/src/main/java/org/apache/kylin/common/kafka/KafkaMsgProducer.java
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.kylin.common.kafka;
+
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kylin.common.KylinConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class KafkaMsgProducer {
+    private static final Logger logger = 
LoggerFactory.getLogger(KafkaMsgProducer.class);
+
+    private static Producer<String, String> producer;
+    private static Map<String, String> kafkaConfig;
+    private static String TOPIC_NAME;
+
+
+    private static Properties kafkaProperties = new Properties() {
+        {
+            put(ProducerConfig.ACKS_CONFIG, "-1");
+            put(ProducerConfig.RETRIES_CONFIG, 3);
+            put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "lz4");
+            put(ProducerConfig.LINGER_MS_CONFIG, 500);
+            put(ProducerConfig.BATCH_SIZE_CONFIG, 10000);
+            put("max.in.flight.requests.per.connection", 1);
+        }
+    };
+
+
+    private KafkaMsgProducer() {
+        init();
+    }
+
+    private static class BasicProducerHolder {
+        private static final KafkaMsgProducer INSTANCE = new 
KafkaMsgProducer();
+    }
+
+    public static final KafkaMsgProducer getInstance() {
+        return BasicProducerHolder.INSTANCE;
+    }
+
+    public void init() {
+        if (null == kafkaConfig) {
+            kafkaConfig = 
KylinConfig.getInstanceFromEnv().getJobStatusKafkaConfig();
+        }
+        if (null == producer) {
+            kafkaProperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, 
kafkaConfig.get("bootstrap.servers"));
+            for(Map.Entry<String, String> entry : kafkaConfig.entrySet()){
+                kafkaProperties.put(entry.getKey(), entry.getValue());
+            }
+            producer = new KafkaProducer<>(kafkaProperties);
+        }
+        if (null == TOPIC_NAME) {
+            TOPIC_NAME = kafkaConfig.get("topic.name");
+        }
+    }
+
+    public void sendJobStatusMessage(String message) {
+        sendMessage(message);
+    }
+
+    public void sendEventMessage(String message) {

Review comment:
       Is this method useless ?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to