You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2019/11/01 07:35:22 UTC

[GitHub] [rocketmq-externals] odbozhou commented on a change in pull request #430: [ISSUE #427]feat(replicator):add consumer offset sync

odbozhou commented on a change in pull request #430: [ISSUE #427]feat(replicator):add consumer offset sync
URL: https://github.com/apache/rocketmq-externals/pull/430#discussion_r341460257
 
 

 ##########
 File path: rocketmq-replicator/src/main/java/org/apache/rocketmq/replicator/MetaSourceTask.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * 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.rocketmq.replicator;
+
+import com.alibaba.fastjson.JSONObject;
+import io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.data.DataEntryBuilder;
+import io.openmessaging.connector.api.data.EntryType;
+import io.openmessaging.connector.api.data.Field;
+import io.openmessaging.connector.api.data.FieldType;
+import io.openmessaging.connector.api.data.Schema;
+import io.openmessaging.connector.api.data.SourceDataEntry;
+import io.openmessaging.connector.api.source.SourceTask;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.ConsumeStats;
+import org.apache.rocketmq.common.admin.OffsetWrapper;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.replicator.common.ConstDefine;
+import org.apache.rocketmq.replicator.common.Utils;
+import org.apache.rocketmq.replicator.config.ConfigUtil;
+import org.apache.rocketmq.replicator.config.TaskConfig;
+import org.apache.rocketmq.replicator.offset.OffsetSyncStore;
+import org.apache.rocketmq.replicator.schema.FieldName;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MetaSourceTask extends SourceTask {
+
+    private static final Logger log = LoggerFactory.getLogger(RmqSourceTask.class);
+
+    private final String taskId;
+    private final TaskConfig config;
+    private DefaultMQAdminExt srcMQAdminExt;
+    private volatile boolean started = false;
+
+    private OffsetSyncStore store;
+
+    public MetaSourceTask() {
+        this.config = new TaskConfig();
+        this.taskId = Utils.createTaskId(Thread.currentThread().getName());
+    }
+
+    @Override public void start(KeyValue config) {
+        ConfigUtil.load(config, this.config);
+
+        startAdmin();
+
+        this.store = new OffsetSyncStore(this.srcMQAdminExt, this.config);
+        this.started = true;
+    }
+
+    @Override public void stop() {
+        if (started) {
+            started = false;
+        }
+    }
+
+    @Override public void pause() {
+
+    }
+
+    @Override public void resume() {
+
+    }
+
+    @Override public Collection<SourceDataEntry> poll() {
+        log.debug("polling...");
+        List<String> groups = JSONObject.parseArray(this.config.getTaskGroupList(), String.class);
+
+        if (groups == null) {
+            log.info("no group in task.");
+            try {
+                Thread.sleep(TimeUnit.SECONDS.toMillis(10));
+            } catch (InterruptedException e) {
+                e.printStackTrace();
 
 Review comment:
   Throw runtime exceptions or print logs better

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services