You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/08/16 07:23:27 UTC

[GitHub] [incubator-seatunnel] EricJoy2048 commented on a diff in pull request #2412: [Feature][Connector-V2] Add Enterprise Wechat sink connector

EricJoy2048 commented on code in PR #2412:
URL: https://github.com/apache/incubator-seatunnel/pull/2412#discussion_r946421261


##########
seatunnel-connectors-v2/connector-http/connector-http-wechat/src/main/java/org/apache/seatunnel/connectors/seatunnel/wechat/sink/WeChatHttpSinkWriter.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.wechat.sink;
+
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.http.config.HttpParameter;
+import org.apache.seatunnel.connectors.seatunnel.http.sink.HttpSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.wechat.sink.config.WeChatSinkConfig;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+public class WeChatHttpSinkWriter extends HttpSinkWriter {
+
+    private final WeChatSinkConfig weChatSinkConfig;
+    private final SeaTunnelRowType seaTunnelRowType;
+
+    public WeChatHttpSinkWriter(HttpParameter httpParameter,  Config pluginConfig, SeaTunnelRowType seaTunnelRowType) {
+        //new SeaTunnelRowType can match SeaTunnelRowWrapper fields sequence
+        super(new SeaTunnelRowType(new String[]{WeChatSinkConfig.WECHAT_SEND_MSG_TYPE_KEY, WeChatSinkConfig.WECHAT_SEND_MSG_SUPPORT_TYPE}, new SeaTunnelDataType[]{BasicType.VOID_TYPE, BasicType.VOID_TYPE}), httpParameter);
+        this.weChatSinkConfig = new WeChatSinkConfig(pluginConfig);
+        this.seaTunnelRowType = seaTunnelRowType;
+    }
+
+    @Override
+    public void write(SeaTunnelRow element) throws IOException {
+        StringBuffer stringBuffer = new StringBuffer();
+        int totalFields = seaTunnelRowType.getTotalFields();
+        for (int i = 0; i < totalFields; i++) {
+            stringBuffer.append(seaTunnelRowType.getFieldName(i) + ": " + element.getField(i) + "\\n");
+        }
+        if (totalFields > 0) {
+            //remove last empty line
+            stringBuffer.delete(stringBuffer.length() - 2, stringBuffer.length());
+        }
+        HashMap<Object, Object> objectMap = new HashMap<>();
+        objectMap.put(WeChatSinkConfig.WECHAT_SEND_MSG_CONTENT_KEY, stringBuffer.toString());
+        if (!weChatSinkConfig.getMentionedMobileList().isEmpty()) {

Review Comment:
   `getMentionedMobileList()` may return `null` value here. So I suggest you use `CollectionUtils.isEmpty` here.



##########
docs/en/connector-v2/sink/Enterprise-WeChat.md:
##########
@@ -0,0 +1,53 @@
+# Enterprise WeChat
+
+> Enterprise WeChat sink connector
+
+## Description
+
+A sink plugin which use Enterprise WeChat robot send message
+> For example, if the data from upstream is [`"告警状态": "firing", "告警时间": "2022-08-03 01:38:49","告警内容": "磁盘使用超出阈值"`], the output content to WeChat Robot is the following:

Review Comment:
   I suggest you change the chinese to english.



-- 
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@seatunnel.apache.org

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