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 2021/10/11 11:30:07 UTC

[GitHub] [rocketmq-externals] Git-Yang opened a new pull request #827: [replicator] Add RmqSinkTask

Git-Yang opened a new pull request #827:
URL: https://github.com/apache/rocketmq-externals/pull/827


   ## What is the purpose of the change
   
   https://github.com/apache/rocketmq-externals/issues/826
   
   ## Brief changelog
   - Add RmqSinkTask.
   - RmqSourceTask adds schema field.
   
   ## Verifying this change
   
   - todo
   
   Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`.
   
   - [x] Make sure there is a [Github issue](https://github.com/apache/rocketmq/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 
   - [x] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in [test module](https://github.com/apache/rocketmq/tree/master/test).
   - [x] Run `mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test`  to make sure integration-test pass.
   - [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas).
   


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] Git-Yang commented on a change in pull request #827: [ISSUE #826] Add RmqSinkTask

Posted by GitBox <gi...@apache.org>.
Git-Yang commented on a change in pull request #827:
URL: https://github.com/apache/rocketmq-externals/pull/827#discussion_r749013296



##########
File path: rocketmq-replicator/src/main/java/org/apache/rocketmq/replicator/RmqSinkTask.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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 io.openmessaging.KeyValue;
+import io.openmessaging.connector.api.common.QueueMetaData;
+import io.openmessaging.connector.api.data.Field;
+import io.openmessaging.connector.api.data.Schema;
+import io.openmessaging.connector.api.data.SinkDataEntry;
+import io.openmessaging.connector.api.sink.SinkTask;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
+import org.apache.rocketmq.acl.common.AclClientRPCHook;
+import org.apache.rocketmq.acl.common.SessionCredentials;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.SendResult;
+import org.apache.rocketmq.client.producer.SendStatus;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.common.message.MessageQueue;
+import org.apache.rocketmq.remoting.RPCHook;
+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.schema.FieldName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RmqSinkTask extends SinkTask {
+
+    private Logger log = LoggerFactory.getLogger(RmqSinkTask.class);
+    private final String taskId;
+    private final TaskConfig taskConfig;
+    private DefaultMQProducer producer;
+    private volatile boolean started = false;
+
+    public RmqSinkTask() {
+        this.taskConfig = new TaskConfig();
+        this.taskId = Utils.createTaskId(Thread.currentThread().getName());
+    }
+
+    @Override
+    public void put(Collection<SinkDataEntry> sinkDataEntries) {
+        for (SinkDataEntry dataEntry : sinkDataEntries) {
+            if (this.started) {
+                Schema schema = dataEntry.getSchema();
+                Object[] payload = dataEntry.getPayload();
+
+                String brokerName = (String) getPayloadValue(FieldName.BROKER_NAME.getKey(), schema, payload);
+                String topic = (String) getPayloadValue(FieldName.TOPIC.getKey(), schema, payload);
+                Integer queueId = (Integer) getPayloadValue(FieldName.QUEUE_ID.getKey(), schema, payload);
+                MessageQueue queue = new MessageQueue(topic, brokerName, queueId);
+
+                String offsetMsgId = (String) getPayloadValue(FieldName.OFFSET_MESSAGE_ID.getKey(), schema, payload);
+                String clientMsgId = (String) getPayloadValue(FieldName.CLIENT_MESSAGE_ID.getKey(), schema, payload);
+                String tags = (String) getPayloadValue(FieldName.TAGS.getKey(), schema, payload);
+                String keys = (String) getPayloadValue(FieldName.KEYS.getKey(), schema, payload);
+                String msgBody = (String) getPayloadValue(FieldName.COMMON_MESSAGE.getKey(), schema, payload);
+                Message msg = new Message();
+                msg.setTopic(topic);
+                msg.setBody(msgBody.getBytes(StandardCharsets.UTF_8));
+                msg.setKeys(String.format("%s %s %s", offsetMsgId, clientMsgId, keys));

Review comment:
       The offsetMsgId is added to the keys, which can be used for message offset checking.




-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] Git-Yang commented on pull request #827: [ISSUE #826] Add RmqSinkTask

Posted by GitBox <gi...@apache.org>.
Git-Yang commented on pull request #827:
URL: https://github.com/apache/rocketmq-externals/pull/827#issuecomment-941939042


   > At first,the origin design is use the target cluster as connector host cluster,In this way, messages can be directly synchronized to another cluster without going through a sink task, and a native format converter is provided in the replicator
   
   First of all, thank you for your answer. What you mean is that the read message is directly written to the local cluster (while serving as the target cluster) through RocketMQConverter. I also agree with this approach. My original intention of adding WorkerDirectTask and RmqSinkTask was to follow the design philosophy of openmessage and reduce intermediate storage. Do you think it makes sense?


-- 
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: dev-unsubscribe@rocketmq.apache.org

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



[GitHub] [rocketmq-externals] Git-Yang commented on pull request #827: [ISSUE #826] Add RmqSinkTask

Posted by GitBox <gi...@apache.org>.
Git-Yang commented on pull request #827:
URL: https://github.com/apache/rocketmq-externals/pull/827#issuecomment-941939042


   > At first,the origin design is use the target cluster as connector host cluster,In this way, messages can be directly synchronized to another cluster without going through a sink task, and a native format converter is provided in the replicator
   
   First of all, thank you for your answer. What you mean is that the read message is directly written to the local cluster (while serving as the target cluster) through RocketMQConverter. I also agree with this approach. My original intention of adding WorkerDirectTask and RmqSinkTask was to follow the design philosophy of openmessage and reduce intermediate storage. Do you think it makes sense?


-- 
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: dev-unsubscribe@rocketmq.apache.org

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