You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/03/18 09:15:31 UTC

[GitHub] [incubator-inlong] pocozh opened a new pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

pocozh opened a new pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227


   ### Title Name: [INLONG-3159][Audit] Store support TubeMQ
   
   Fixes #3159 
   
   ### Motivation
   
   *Explain here the context, and why you're making that change. What is the problem you're trying to solve.*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   


-- 
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] [incubator-inlong] baomingyu commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
baomingyu commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830442702



##########
File path: inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/config/MessageQueueConfig.java
##########
@@ -47,4 +48,27 @@
     @Value("${audit.pulsar.client.concurrent.consumer.num:1}")
     private int concurrentConsumerNum = 1;
 
+    @Value("${audit.tube.masterlist}")
+    private String tubeMasterList;

Review comment:
       this is optional config, so need config default value.

##########
File path: inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/consume/TubeConsume.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.audit.service.consume;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.inlong.audit.config.MessageQueueConfig;
+import org.apache.inlong.audit.config.StoreConfig;
+import org.apache.inlong.audit.db.dao.AuditDataDao;
+import org.apache.inlong.audit.service.ElasticsearchService;
+import org.apache.inlong.tubemq.client.config.ConsumerConfig;
+import org.apache.inlong.tubemq.client.consumer.ConsumePosition;
+import org.apache.inlong.tubemq.client.consumer.ConsumerResult;
+import org.apache.inlong.tubemq.client.consumer.PullMessageConsumer;
+import org.apache.inlong.tubemq.client.exception.TubeClientException;
+import org.apache.inlong.tubemq.client.factory.TubeMultiSessionFactory;
+import org.apache.inlong.tubemq.corebase.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class TubeConsume extends BaseConsume {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TubeConsume.class);
+    private PullMessageConsumer pullConsumer;
+    private TubeMultiSessionFactory sessionFactory;
+    private String masterUrl;
+    private String topic;
+    private int fetchThreadCnt = 4;
+
+    public TubeConsume(AuditDataDao auditDataDao, ElasticsearchService esService, StoreConfig storeConfig,
+            MessageQueueConfig mqConfig) {
+        super(auditDataDao, esService, storeConfig, mqConfig);
+    }
+
+    @Override
+    public void start() {
+        masterUrl = mqConfig.getTubeMasterList();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(masterUrl), "no tube masterUrlList specified");
+        topic = mqConfig.getTubeTopic();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(topic), "no tube topic specified");
+        fetchThreadCnt = mqConfig.getTubeThreadNum();
+
+        initConsumer();
+
+        Thread[] fetchRunners = new Thread[fetchThreadCnt];
+        for (int i = 0; i < fetchThreadCnt; i++) {
+            fetchRunners[i] = new Thread(new Fetcher(pullConsumer, topic), "TubeConsume_Fetcher_Thread_" + i);
+            fetchRunners[i].start();
+        }
+    }
+
+    private void initConsumer() {
+        LOG.info("init tube consumer, topic:{}, masterList:{}", topic, masterUrl);
+        ConsumerConfig consumerConfig = new ConsumerConfig(masterUrl, mqConfig.getTubeConsumerGroupName());
+        consumerConfig.setConsumePosition(ConsumePosition.CONSUMER_FROM_LATEST_OFFSET);
+        try {
+            sessionFactory = new TubeMultiSessionFactory(consumerConfig);
+            pullConsumer = sessionFactory.createPullConsumer(consumerConfig);
+            pullConsumer.subscribe(topic, null);
+            pullConsumer.completeSubscribe();
+        } catch (TubeClientException e) {
+            LOG.error("init tube consumer error {}", e.getMessage());
+        }
+
+    }
+
+    public class Fetcher implements Runnable {
+
+        private final PullMessageConsumer pullMessageConsumer;
+        private String topic;
+
+        public Fetcher(PullMessageConsumer pullMessageConsumer, String topic) {
+            this.pullMessageConsumer = pullMessageConsumer;
+            this.topic = topic;
+        }
+
+        @Override
+        public void run() {
+            ConsumerResult csmResult;
+
+            // wait partition status ready
+            while (true) {
+                if (pullMessageConsumer.isPartitionsReady(5000) || pullMessageConsumer.isShutdown()) {

Review comment:
       add this stat log.

##########
File path: inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/consume/TubeConsume.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.audit.service.consume;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.inlong.audit.config.MessageQueueConfig;
+import org.apache.inlong.audit.config.StoreConfig;
+import org.apache.inlong.audit.db.dao.AuditDataDao;
+import org.apache.inlong.audit.service.ElasticsearchService;
+import org.apache.inlong.tubemq.client.config.ConsumerConfig;
+import org.apache.inlong.tubemq.client.consumer.ConsumePosition;
+import org.apache.inlong.tubemq.client.consumer.ConsumerResult;
+import org.apache.inlong.tubemq.client.consumer.PullMessageConsumer;
+import org.apache.inlong.tubemq.client.exception.TubeClientException;
+import org.apache.inlong.tubemq.client.factory.TubeMultiSessionFactory;
+import org.apache.inlong.tubemq.corebase.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class TubeConsume extends BaseConsume {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TubeConsume.class);
+    private PullMessageConsumer pullConsumer;
+    private TubeMultiSessionFactory sessionFactory;
+    private String masterUrl;
+    private String topic;
+    private int fetchThreadCnt = 4;
+
+    public TubeConsume(AuditDataDao auditDataDao, ElasticsearchService esService, StoreConfig storeConfig,
+            MessageQueueConfig mqConfig) {
+        super(auditDataDao, esService, storeConfig, mqConfig);
+    }
+
+    @Override
+    public void start() {
+        masterUrl = mqConfig.getTubeMasterList();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(masterUrl), "no tube masterUrlList specified");
+        topic = mqConfig.getTubeTopic();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(topic), "no tube topic specified");
+        fetchThreadCnt = mqConfig.getTubeThreadNum();
+
+        initConsumer();
+
+        Thread[] fetchRunners = new Thread[fetchThreadCnt];
+        for (int i = 0; i < fetchThreadCnt; i++) {
+            fetchRunners[i] = new Thread(new Fetcher(pullConsumer, topic), "TubeConsume_Fetcher_Thread_" + i);
+            fetchRunners[i].start();
+        }
+    }
+
+    private void initConsumer() {
+        LOG.info("init tube consumer, topic:{}, masterList:{}", topic, masterUrl);
+        ConsumerConfig consumerConfig = new ConsumerConfig(masterUrl, mqConfig.getTubeConsumerGroupName());
+        consumerConfig.setConsumePosition(ConsumePosition.CONSUMER_FROM_LATEST_OFFSET);
+        try {
+            sessionFactory = new TubeMultiSessionFactory(consumerConfig);
+            pullConsumer = sessionFactory.createPullConsumer(consumerConfig);
+            pullConsumer.subscribe(topic, null);
+            pullConsumer.completeSubscribe();
+        } catch (TubeClientException e) {
+            LOG.error("init tube consumer error {}", e.getMessage());
+        }
+
+    }
+
+    public class Fetcher implements Runnable {
+
+        private final PullMessageConsumer pullMessageConsumer;
+        private String topic;
+
+        public Fetcher(PullMessageConsumer pullMessageConsumer, String topic) {
+            this.pullMessageConsumer = pullMessageConsumer;
+            this.topic = topic;
+        }
+
+        @Override
+        public void run() {
+            ConsumerResult csmResult;
+
+            // wait partition status ready
+            while (true) {
+                if (pullMessageConsumer.isPartitionsReady(5000) || pullMessageConsumer.isShutdown()) {
+                    break;
+                }
+            }
+            // consume messages
+            while (true) {
+                if (pullMessageConsumer.isShutdown()) {
+                    LOG.warn("consumer is shutdown!");
+                    break;
+                }
+
+                try {
+                    csmResult = pullMessageConsumer.getMessage();
+                    if (csmResult.isSuccess()) {
+                        List<Message> messageList = csmResult.getMessageList();
+                        if (CollectionUtils.isNotEmpty(messageList)) {
+                            for (Message message : messageList) {
+                                if (StringUtils.equals(message.getTopic(), topic)) {
+                                    String body = new String(message.getData(), StandardCharsets.UTF_8);
+                                    handleMessage(body);
+                                }
+                            }
+                        }
+                        pullMessageConsumer.confirmConsume(csmResult.getConfirmContext(), true);
+                    } else {
+                        //TODO improve error handle
+                        LOG.error("receive messages errorCode is {}, error meddage is {}", csmResult.getErrCode(),

Review comment:
       Does this branch need ack?




-- 
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] [incubator-inlong] dockerzhang merged pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
dockerzhang merged pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227


   


-- 
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] [incubator-inlong] healchow commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
healchow commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830038782



##########
File path: inlong-audit/audit-store/src/test/resources/application-test.properties
##########
@@ -16,16 +16,13 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-

Review comment:
       It is recommended to keep these blank lines to make the properties file more readable.




-- 
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] [incubator-inlong] pocozh commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
pocozh commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830712665



##########
File path: inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/consume/TubeConsume.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.audit.service.consume;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.inlong.audit.config.MessageQueueConfig;
+import org.apache.inlong.audit.config.StoreConfig;
+import org.apache.inlong.audit.db.dao.AuditDataDao;
+import org.apache.inlong.audit.service.ElasticsearchService;
+import org.apache.inlong.tubemq.client.config.ConsumerConfig;
+import org.apache.inlong.tubemq.client.consumer.ConsumePosition;
+import org.apache.inlong.tubemq.client.consumer.ConsumerResult;
+import org.apache.inlong.tubemq.client.consumer.PullMessageConsumer;
+import org.apache.inlong.tubemq.client.exception.TubeClientException;
+import org.apache.inlong.tubemq.client.factory.TubeMultiSessionFactory;
+import org.apache.inlong.tubemq.corebase.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class TubeConsume extends BaseConsume {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TubeConsume.class);
+    private PullMessageConsumer pullConsumer;
+    private TubeMultiSessionFactory sessionFactory;
+    private String masterUrl;
+    private String topic;
+    private int fetchThreadCnt = 4;
+
+    public TubeConsume(AuditDataDao auditDataDao, ElasticsearchService esService, StoreConfig storeConfig,
+            MessageQueueConfig mqConfig) {
+        super(auditDataDao, esService, storeConfig, mqConfig);
+    }
+
+    @Override
+    public void start() {
+        masterUrl = mqConfig.getTubeMasterList();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(masterUrl), "no tube masterUrlList specified");
+        topic = mqConfig.getTubeTopic();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(topic), "no tube topic specified");
+        fetchThreadCnt = mqConfig.getTubeThreadNum();
+
+        initConsumer();
+
+        Thread[] fetchRunners = new Thread[fetchThreadCnt];
+        for (int i = 0; i < fetchThreadCnt; i++) {
+            fetchRunners[i] = new Thread(new Fetcher(pullConsumer, topic), "TubeConsume_Fetcher_Thread_" + i);
+            fetchRunners[i].start();
+        }
+    }
+
+    private void initConsumer() {
+        LOG.info("init tube consumer, topic:{}, masterList:{}", topic, masterUrl);
+        ConsumerConfig consumerConfig = new ConsumerConfig(masterUrl, mqConfig.getTubeConsumerGroupName());
+        consumerConfig.setConsumePosition(ConsumePosition.CONSUMER_FROM_LATEST_OFFSET);
+        try {
+            sessionFactory = new TubeMultiSessionFactory(consumerConfig);
+            pullConsumer = sessionFactory.createPullConsumer(consumerConfig);
+            pullConsumer.subscribe(topic, null);
+            pullConsumer.completeSubscribe();
+        } catch (TubeClientException e) {
+            LOG.error("init tube consumer error {}", e.getMessage());
+        }
+
+    }
+
+    public class Fetcher implements Runnable {
+
+        private final PullMessageConsumer pullMessageConsumer;
+        private String topic;
+
+        public Fetcher(PullMessageConsumer pullMessageConsumer, String topic) {
+            this.pullMessageConsumer = pullMessageConsumer;
+            this.topic = topic;
+        }
+
+        @Override
+        public void run() {
+            ConsumerResult csmResult;
+
+            // wait partition status ready
+            while (true) {
+                if (pullMessageConsumer.isPartitionsReady(5000) || pullMessageConsumer.isShutdown()) {

Review comment:
       donw




-- 
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] [incubator-inlong] healchow commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
healchow commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830038782



##########
File path: inlong-audit/audit-store/src/test/resources/application-test.properties
##########
@@ -16,16 +16,13 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-

Review comment:
       It is recommended to keep these blank lines to make the properties file more readable.




-- 
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] [incubator-inlong] pocozh commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
pocozh commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830711349



##########
File path: inlong-audit/audit-store/src/test/resources/application-test.properties
##########
@@ -16,16 +16,13 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-

Review comment:
       ok




-- 
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] [incubator-inlong] pocozh commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
pocozh commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830720675



##########
File path: inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/service/consume/TubeConsume.java
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.audit.service.consume;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.inlong.audit.config.MessageQueueConfig;
+import org.apache.inlong.audit.config.StoreConfig;
+import org.apache.inlong.audit.db.dao.AuditDataDao;
+import org.apache.inlong.audit.service.ElasticsearchService;
+import org.apache.inlong.tubemq.client.config.ConsumerConfig;
+import org.apache.inlong.tubemq.client.consumer.ConsumePosition;
+import org.apache.inlong.tubemq.client.consumer.ConsumerResult;
+import org.apache.inlong.tubemq.client.consumer.PullMessageConsumer;
+import org.apache.inlong.tubemq.client.exception.TubeClientException;
+import org.apache.inlong.tubemq.client.factory.TubeMultiSessionFactory;
+import org.apache.inlong.tubemq.corebase.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class TubeConsume extends BaseConsume {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TubeConsume.class);
+    private PullMessageConsumer pullConsumer;
+    private TubeMultiSessionFactory sessionFactory;
+    private String masterUrl;
+    private String topic;
+    private int fetchThreadCnt = 4;
+
+    public TubeConsume(AuditDataDao auditDataDao, ElasticsearchService esService, StoreConfig storeConfig,
+            MessageQueueConfig mqConfig) {
+        super(auditDataDao, esService, storeConfig, mqConfig);
+    }
+
+    @Override
+    public void start() {
+        masterUrl = mqConfig.getTubeMasterList();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(masterUrl), "no tube masterUrlList specified");
+        topic = mqConfig.getTubeTopic();
+        Preconditions.checkArgument(StringUtils.isNotEmpty(topic), "no tube topic specified");
+        fetchThreadCnt = mqConfig.getTubeThreadNum();
+
+        initConsumer();
+
+        Thread[] fetchRunners = new Thread[fetchThreadCnt];
+        for (int i = 0; i < fetchThreadCnt; i++) {
+            fetchRunners[i] = new Thread(new Fetcher(pullConsumer, topic), "TubeConsume_Fetcher_Thread_" + i);
+            fetchRunners[i].start();
+        }
+    }
+
+    private void initConsumer() {
+        LOG.info("init tube consumer, topic:{}, masterList:{}", topic, masterUrl);
+        ConsumerConfig consumerConfig = new ConsumerConfig(masterUrl, mqConfig.getTubeConsumerGroupName());
+        consumerConfig.setConsumePosition(ConsumePosition.CONSUMER_FROM_LATEST_OFFSET);
+        try {
+            sessionFactory = new TubeMultiSessionFactory(consumerConfig);
+            pullConsumer = sessionFactory.createPullConsumer(consumerConfig);
+            pullConsumer.subscribe(topic, null);
+            pullConsumer.completeSubscribe();
+        } catch (TubeClientException e) {
+            LOG.error("init tube consumer error {}", e.getMessage());
+        }
+
+    }
+
+    public class Fetcher implements Runnable {
+
+        private final PullMessageConsumer pullMessageConsumer;
+        private String topic;
+
+        public Fetcher(PullMessageConsumer pullMessageConsumer, String topic) {
+            this.pullMessageConsumer = pullMessageConsumer;
+            this.topic = topic;
+        }
+
+        @Override
+        public void run() {
+            ConsumerResult csmResult;
+
+            // wait partition status ready
+            while (true) {
+                if (pullMessageConsumer.isPartitionsReady(5000) || pullMessageConsumer.isShutdown()) {
+                    break;
+                }
+            }
+            // consume messages
+            while (true) {
+                if (pullMessageConsumer.isShutdown()) {
+                    LOG.warn("consumer is shutdown!");
+                    break;
+                }
+
+                try {
+                    csmResult = pullMessageConsumer.getMessage();
+                    if (csmResult.isSuccess()) {
+                        List<Message> messageList = csmResult.getMessageList();
+                        if (CollectionUtils.isNotEmpty(messageList)) {
+                            for (Message message : messageList) {
+                                if (StringUtils.equals(message.getTopic(), topic)) {
+                                    String body = new String(message.getData(), StandardCharsets.UTF_8);
+                                    handleMessage(body);
+                                }
+                            }
+                        }
+                        pullMessageConsumer.confirmConsume(csmResult.getConfirmContext(), true);
+                    } else {
+                        //TODO improve error handle
+                        LOG.error("receive messages errorCode is {}, error meddage is {}", csmResult.getErrCode(),

Review comment:
       no need




-- 
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] [incubator-inlong] pocozh commented on a change in pull request #3227: [INLONG-3159][Audit] Store support TubeMQ

Posted by GitBox <gi...@apache.org>.
pocozh commented on a change in pull request #3227:
URL: https://github.com/apache/incubator-inlong/pull/3227#discussion_r830707905



##########
File path: inlong-audit/audit-store/src/main/java/org/apache/inlong/audit/config/MessageQueueConfig.java
##########
@@ -47,4 +48,27 @@
     @Value("${audit.pulsar.client.concurrent.consumer.num:1}")
     private int concurrentConsumerNum = 1;
 
+    @Value("${audit.tube.masterlist}")
+    private String tubeMasterList;

Review comment:
       done




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