You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "wangpeix (via GitHub)" <gi...@apache.org> on 2023/04/09 12:01:23 UTC

[GitHub] [inlong] wangpeix opened a new pull request, #7808: [INLONG-7783][Agent] Support kafka sink

wangpeix opened a new pull request, #7808:
URL: https://github.com/apache/inlong/pull/7808

   ### Prepare a Pull Request
   - Title: [INLONG-7783][Agent] Support kafka sink
   - Fixes #7783 
   
   ### Motivation
   
   Agent support kafka sink.
   
   ### Modifications
   
   Extend `AbstractSink` to implement `KafkaSink`.


-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] haifxu commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "haifxu (via GitHub)" <gi...@apache.org>.
haifxu commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162233642


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   It may be better to use `groupEntity.getMqResource()` + DOT + `streamEntity.getMqResource()` in this place.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] dockerzhang merged pull request #7808: [INLONG-7783][Agent] Support sink data to Kafka

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang merged PR #7808:
URL: https://github.com/apache/inlong/pull/7808


-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1161645152


##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java:
##########
@@ -171,12 +171,26 @@ public class AgentConstants {
     public static final String DEFAULT_COMPRESSION_TYPE = "NONE";
 
     public static final String PULSAR_CLIENT_PRODUCER_NUM = "agent.sink.pulsar.producer.num";
+    public static final String KAFKA_SINK_PRODUCER_NUM = "agent.sink.kafka.producer.num";

Review Comment:
   Suggested naming it like Pulsar, for example:
   
   ```suggestion
       public static final String KAFKA_CLIENT_PRODUCER_NUM = "agent.sink.kafka.producer.num";
   ```



##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java:
##########
@@ -171,12 +171,26 @@ public class AgentConstants {
     public static final String DEFAULT_COMPRESSION_TYPE = "NONE";
 
     public static final String PULSAR_CLIENT_PRODUCER_NUM = "agent.sink.pulsar.producer.num";
+    public static final String KAFKA_SINK_PRODUCER_NUM = "agent.sink.kafka.producer.num";
     public static final int DEFAULT_PRODUCER_NUM = 3;
 
     public static final String PULSAR_CLIENT_ENABLE_ASYNC_SEND = "agent.sink.pulsar.enbale.async.send";
+    public static final String KAFKA_PRODUCER_ENABLE_ASYNC_SEND = "agent.sink.kafka.enbale.async.send";

Review Comment:
   ditto.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] haifxu commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "haifxu (via GitHub)" <gi...@apache.org>.
haifxu commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1161513365


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   Why not use `mqResource`?



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data to Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162445123


##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sinks/KafkaSink.java:
##########
@@ -0,0 +1,445 @@
+/*
+ * 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.inlong.agent.plugin.sinks;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.agent.common.AgentThreadFactory;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.conf.JobProfile;
+import org.apache.inlong.agent.core.task.TaskPositionManager;
+import org.apache.inlong.agent.message.BatchProxyMessage;
+import org.apache.inlong.agent.message.EndMessage;
+import org.apache.inlong.agent.message.PackProxyMessage;
+import org.apache.inlong.agent.message.ProxyMessage;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.plugin.Message;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.dataproxy.MQClusterInfo;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_ACKS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_COMPRESSION_TYPE;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_KEY_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_VALUE_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SYNC_SEND_TIMEOUT_MS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_SEND_QUEUE_SIZE;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_PRODUCER_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_SEND_QUEUE_SIZE;
+import static org.apache.kafka.clients.CommonClientConfigs.SECURITY_PROTOCOL_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_JAAS_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_MECHANISM;
+
+public class KafkaSink extends AbstractSink {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(KafkaSink.class);
+    private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+            60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new AgentThreadFactory("KafkaSink"));
+    private final AgentConfiguration agentConf = AgentConfiguration.getAgentConf();
+    private TaskPositionManager taskPositionManager;
+    private volatile boolean shutdown = false;
+
+    private List<MQClusterInfo> mqClusterInfos;
+    private String topic;
+    private List<KafkaSender> kafkaSenders;
+    private static final AtomicInteger KAFKA_SENDER_INDEX = new AtomicInteger(0);
+
+    private LinkedBlockingQueue<BatchProxyMessage> kafkaSendQueue;
+
+    private int producerNum;
+    private boolean asyncSend;
+
+    @Override
+    public void init(JobProfile jobConf) {
+        super.init(jobConf);
+        taskPositionManager = TaskPositionManager.getInstance();
+        int sendQueueSize = agentConf.getInt(KAFKA_SINK_SEND_QUEUE_SIZE, DEFAULT_SEND_QUEUE_SIZE);
+        kafkaSendQueue = new LinkedBlockingQueue<>(sendQueueSize);
+        producerNum = agentConf.getInt(KAFKA_SINK_PRODUCER_NUM, DEFAULT_PRODUCER_NUM);
+        asyncSend = agentConf.getBoolean(KAFKA_PRODUCER_ENABLE_ASYNC_SEND, DEFAULT_ENABLE_ASYNC_SEND);
+
+        mqClusterInfos = jobConf.getMqClusters();
+        Preconditions.checkArgument(ObjectUtils.isNotEmpty(jobConf.getMqTopic()) && jobConf.getMqTopic().isValid(),
+                "no valid kafka topic config");
+        topic = jobConf.getMqTopic().getTopic();
+
+        kafkaSenders = new ArrayList<>();
+        initKafkaSender();
+        EXECUTOR_SERVICE.execute(sendDataThread());
+        EXECUTOR_SERVICE.execute(flushCache());
+    }
+
+    @Override
+    public void write(Message message) {
+        try {
+            if (message != null) {

Review Comment:
   The nesting of this code is too deep, it is recommended to use guard statements(卫语句) to simplify.
   
   For example:
   ```java
   if (message == null) {
       return;
   }
   
   // other process in else
   ```
   



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] haifxu commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "haifxu (via GitHub)" <gi...@apache.org>.
haifxu commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1161513365


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   Why not use `mqResource`?



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] wangpeix commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data to Kafka

Posted by "wangpeix (via GitHub)" <gi...@apache.org>.
wangpeix commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162456749


##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sinks/KafkaSink.java:
##########
@@ -0,0 +1,445 @@
+/*
+ * 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.inlong.agent.plugin.sinks;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.agent.common.AgentThreadFactory;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.conf.JobProfile;
+import org.apache.inlong.agent.core.task.TaskPositionManager;
+import org.apache.inlong.agent.message.BatchProxyMessage;
+import org.apache.inlong.agent.message.EndMessage;
+import org.apache.inlong.agent.message.PackProxyMessage;
+import org.apache.inlong.agent.message.ProxyMessage;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.plugin.Message;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.dataproxy.MQClusterInfo;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_ACKS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_COMPRESSION_TYPE;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_KEY_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_VALUE_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SYNC_SEND_TIMEOUT_MS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_SEND_QUEUE_SIZE;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_PRODUCER_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_SEND_QUEUE_SIZE;
+import static org.apache.kafka.clients.CommonClientConfigs.SECURITY_PROTOCOL_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_JAAS_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_MECHANISM;
+
+public class KafkaSink extends AbstractSink {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(KafkaSink.class);
+    private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+            60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new AgentThreadFactory("KafkaSink"));
+    private final AgentConfiguration agentConf = AgentConfiguration.getAgentConf();
+    private TaskPositionManager taskPositionManager;
+    private volatile boolean shutdown = false;
+
+    private List<MQClusterInfo> mqClusterInfos;
+    private String topic;
+    private List<KafkaSender> kafkaSenders;
+    private static final AtomicInteger KAFKA_SENDER_INDEX = new AtomicInteger(0);
+
+    private LinkedBlockingQueue<BatchProxyMessage> kafkaSendQueue;
+
+    private int producerNum;
+    private boolean asyncSend;
+
+    @Override
+    public void init(JobProfile jobConf) {
+        super.init(jobConf);
+        taskPositionManager = TaskPositionManager.getInstance();
+        int sendQueueSize = agentConf.getInt(KAFKA_SINK_SEND_QUEUE_SIZE, DEFAULT_SEND_QUEUE_SIZE);
+        kafkaSendQueue = new LinkedBlockingQueue<>(sendQueueSize);
+        producerNum = agentConf.getInt(KAFKA_SINK_PRODUCER_NUM, DEFAULT_PRODUCER_NUM);
+        asyncSend = agentConf.getBoolean(KAFKA_PRODUCER_ENABLE_ASYNC_SEND, DEFAULT_ENABLE_ASYNC_SEND);
+
+        mqClusterInfos = jobConf.getMqClusters();
+        Preconditions.checkArgument(ObjectUtils.isNotEmpty(jobConf.getMqTopic()) && jobConf.getMqTopic().isValid(),
+                "no valid kafka topic config");
+        topic = jobConf.getMqTopic().getTopic();
+
+        kafkaSenders = new ArrayList<>();
+        initKafkaSender();
+        EXECUTOR_SERVICE.execute(sendDataThread());
+        EXECUTOR_SERVICE.execute(flushCache());
+    }
+
+    @Override
+    public void write(Message message) {
+        try {
+            if (message != null) {

Review Comment:
   Okay, thx. I'll optimize it.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] wangpeix commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "wangpeix (via GitHub)" <gi...@apache.org>.
wangpeix commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1161689997


##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java:
##########
@@ -171,12 +171,26 @@ public class AgentConstants {
     public static final String DEFAULT_COMPRESSION_TYPE = "NONE";
 
     public static final String PULSAR_CLIENT_PRODUCER_NUM = "agent.sink.pulsar.producer.num";
+    public static final String KAFKA_SINK_PRODUCER_NUM = "agent.sink.kafka.producer.num";

Review Comment:
   The usage of pulsar and kafka is different. To send data using pulsar, need to first create a client; Sending data using Kafka does not require creating a client, just creating a producer. In Kafka, not using the `CLIENT` variable name may be more suitable.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1161646981


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   @haifxu Can you please check how Kafka topics are spliced in InLong?



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] wangpeix commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "wangpeix (via GitHub)" <gi...@apache.org>.
wangpeix commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162241142


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   Okay, thanks. I'll optimize it.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] haifxu commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "haifxu (via GitHub)" <gi...@apache.org>.
haifxu commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162231792


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   `InlongGroupInfo.mqResource` + dot + `InlongStreamInfo.mqResource`.
   So the default value should be `groupId` + dot + `streamId`.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data to Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162445123


##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sinks/KafkaSink.java:
##########
@@ -0,0 +1,445 @@
+/*
+ * 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.inlong.agent.plugin.sinks;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.agent.common.AgentThreadFactory;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.conf.JobProfile;
+import org.apache.inlong.agent.core.task.TaskPositionManager;
+import org.apache.inlong.agent.message.BatchProxyMessage;
+import org.apache.inlong.agent.message.EndMessage;
+import org.apache.inlong.agent.message.PackProxyMessage;
+import org.apache.inlong.agent.message.ProxyMessage;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.plugin.Message;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.dataproxy.MQClusterInfo;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_ACKS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_COMPRESSION_TYPE;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_KEY_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_VALUE_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SYNC_SEND_TIMEOUT_MS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_SEND_QUEUE_SIZE;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_PRODUCER_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_SEND_QUEUE_SIZE;
+import static org.apache.kafka.clients.CommonClientConfigs.SECURITY_PROTOCOL_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_JAAS_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_MECHANISM;
+
+public class KafkaSink extends AbstractSink {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(KafkaSink.class);
+    private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+            60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new AgentThreadFactory("KafkaSink"));
+    private final AgentConfiguration agentConf = AgentConfiguration.getAgentConf();
+    private TaskPositionManager taskPositionManager;
+    private volatile boolean shutdown = false;
+
+    private List<MQClusterInfo> mqClusterInfos;
+    private String topic;
+    private List<KafkaSender> kafkaSenders;
+    private static final AtomicInteger KAFKA_SENDER_INDEX = new AtomicInteger(0);
+
+    private LinkedBlockingQueue<BatchProxyMessage> kafkaSendQueue;
+
+    private int producerNum;
+    private boolean asyncSend;
+
+    @Override
+    public void init(JobProfile jobConf) {
+        super.init(jobConf);
+        taskPositionManager = TaskPositionManager.getInstance();
+        int sendQueueSize = agentConf.getInt(KAFKA_SINK_SEND_QUEUE_SIZE, DEFAULT_SEND_QUEUE_SIZE);
+        kafkaSendQueue = new LinkedBlockingQueue<>(sendQueueSize);
+        producerNum = agentConf.getInt(KAFKA_SINK_PRODUCER_NUM, DEFAULT_PRODUCER_NUM);
+        asyncSend = agentConf.getBoolean(KAFKA_PRODUCER_ENABLE_ASYNC_SEND, DEFAULT_ENABLE_ASYNC_SEND);
+
+        mqClusterInfos = jobConf.getMqClusters();
+        Preconditions.checkArgument(ObjectUtils.isNotEmpty(jobConf.getMqTopic()) && jobConf.getMqTopic().isValid(),
+                "no valid kafka topic config");
+        topic = jobConf.getMqTopic().getTopic();
+
+        kafkaSenders = new ArrayList<>();
+        initKafkaSender();
+        EXECUTOR_SERVICE.execute(sendDataThread());
+        EXECUTOR_SERVICE.execute(flushCache());
+    }
+
+    @Override
+    public void write(Message message) {
+        try {
+            if (message != null) {

Review Comment:
   The nesting of this code is too deep, it is recommended to use guard statements to simplify.
   
   For example:
   ```java
   if (message == null) {
       return;
   }
   
   // other process in else
   ```
   



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162238710


##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AgentServiceImpl.java:
##########
@@ -518,6 +519,11 @@ private DataConfig getDataConfig(StreamSourceEntity entity, int op) {
                     topicConfig.setInlongGroupId(groupId);
                     topicConfig.setTopic(mqResource);
                     dataConfig.setTopicInfo(topicConfig);
+                } else if (MQType.KAFKA.equals(mqType)) {
+                    DataProxyTopicInfo topicConfig = new DataProxyTopicInfo();
+                    topicConfig.setInlongGroupId(groupId);
+                    topicConfig.setTopic(groupId + DOT + streamId);

Review Comment:
   > It may be better to use `groupEntity.getMqResource()` + DOT + `streamEntity.getMqResource()` in this place.
   
   cc @wangpeix 
   



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data tor Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162238341


##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/constant/AgentConstants.java:
##########
@@ -171,12 +171,26 @@ public class AgentConstants {
     public static final String DEFAULT_COMPRESSION_TYPE = "NONE";
 
     public static final String PULSAR_CLIENT_PRODUCER_NUM = "agent.sink.pulsar.producer.num";
+    public static final String KAFKA_SINK_PRODUCER_NUM = "agent.sink.kafka.producer.num";

Review Comment:
   Okay.



-- 
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: commits-unsubscribe@inlong.apache.org

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


[GitHub] [inlong] healchow commented on a diff in pull request #7808: [INLONG-7783][Agent] Support sink data to Kafka

Posted by "healchow (via GitHub)" <gi...@apache.org>.
healchow commented on code in PR #7808:
URL: https://github.com/apache/inlong/pull/7808#discussion_r1162600594


##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sinks/KafkaSink.java:
##########
@@ -0,0 +1,446 @@
+/*
+ * 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.inlong.agent.plugin.sinks;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.agent.common.AgentThreadFactory;
+import org.apache.inlong.agent.conf.AgentConfiguration;
+import org.apache.inlong.agent.conf.JobProfile;
+import org.apache.inlong.agent.core.task.TaskPositionManager;
+import org.apache.inlong.agent.message.BatchProxyMessage;
+import org.apache.inlong.agent.message.EndMessage;
+import org.apache.inlong.agent.message.PackProxyMessage;
+import org.apache.inlong.agent.message.ProxyMessage;
+import org.apache.inlong.agent.metrics.audit.AuditUtils;
+import org.apache.inlong.agent.plugin.Message;
+import org.apache.inlong.agent.utils.AgentUtils;
+import org.apache.inlong.agent.utils.ThreadUtils;
+import org.apache.inlong.common.pojo.dataproxy.MQClusterInfo;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_ACKS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_COMPRESSION_TYPE;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_KEY_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SEND_VALUE_SERIALIZER;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_KAFKA_SINK_SYNC_SEND_TIMEOUT_MS;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.DEFAULT_SEND_QUEUE_SIZE;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_PRODUCER_ENABLE_ASYNC_SEND;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_PRODUCER_NUM;
+import static org.apache.inlong.agent.constant.AgentConstants.KAFKA_SINK_SEND_QUEUE_SIZE;
+import static org.apache.kafka.clients.CommonClientConfigs.SECURITY_PROTOCOL_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_JAAS_CONFIG;
+import static org.apache.kafka.common.config.SaslConfigs.SASL_MECHANISM;
+
+public class KafkaSink extends AbstractSink {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(KafkaSink.class);
+    private static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+            60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new AgentThreadFactory("KafkaSink"));
+    private final AgentConfiguration agentConf = AgentConfiguration.getAgentConf();
+    private TaskPositionManager taskPositionManager;
+    private volatile boolean shutdown = false;
+
+    private List<MQClusterInfo> mqClusterInfos;
+    private String topic;
+    private List<KafkaSender> kafkaSenders;
+    private static final AtomicInteger KAFKA_SENDER_INDEX = new AtomicInteger(0);
+
+    private LinkedBlockingQueue<BatchProxyMessage> kafkaSendQueue;
+
+    private int producerNum;
+    private boolean asyncSend;
+
+    @Override
+    public void init(JobProfile jobConf) {
+        super.init(jobConf);
+        taskPositionManager = TaskPositionManager.getInstance();
+        int sendQueueSize = agentConf.getInt(KAFKA_SINK_SEND_QUEUE_SIZE, DEFAULT_SEND_QUEUE_SIZE);
+        kafkaSendQueue = new LinkedBlockingQueue<>(sendQueueSize);
+        producerNum = agentConf.getInt(KAFKA_SINK_PRODUCER_NUM, DEFAULT_PRODUCER_NUM);
+        asyncSend = agentConf.getBoolean(KAFKA_PRODUCER_ENABLE_ASYNC_SEND, DEFAULT_ENABLE_ASYNC_SEND);
+
+        mqClusterInfos = jobConf.getMqClusters();
+        Preconditions.checkArgument(ObjectUtils.isNotEmpty(jobConf.getMqTopic()) && jobConf.getMqTopic().isValid(),
+                "no valid kafka topic config");
+        topic = jobConf.getMqTopic().getTopic();
+
+        kafkaSenders = new ArrayList<>();
+        initKafkaSender();
+        EXECUTOR_SERVICE.execute(sendDataThread());
+        EXECUTOR_SERVICE.execute(flushCache());
+    }
+
+    @Override
+    public void write(Message message) {
+        if (message == null) {
+            return;
+        }
+
+        if (message instanceof EndMessage) {
+            return;
+        }

Review Comment:
   ```suggestion
           if (message == null || message instanceof EndMessage) {
               return;
           }
   ```



-- 
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: commits-unsubscribe@inlong.apache.org

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