pandaapo commented on code in PR #4557: URL: https://github.com/apache/eventmesh/pull/4557#discussion_r1394067206
########## eventmesh-connectors/eventmesh-connector-dingding/src/main/java/org/apache/eventmesh/connector/dingding/sink/connector/DingDingSinkConnector.java: ########## @@ -0,0 +1,178 @@ +/* + * 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.eventmesh.connector.dingding.sink.connector; + +import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.connector.dingding.config.DingDingMessageTemplateType; +import org.apache.eventmesh.connector.dingding.sink.config.DingDingSinkConfig; +import org.apache.eventmesh.openconnect.api.config.Config; +import org.apache.eventmesh.openconnect.api.connector.ConnectorContext; +import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext; +import org.apache.eventmesh.openconnect.api.sink.Sink; +import org.apache.eventmesh.openconnect.offsetmgmt.api.constants.ConnectRecordExtensionKeys; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +import com.aliyun.tea.TeaException; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + +import lombok.SneakyThrows; + +public class DingDingSinkConnector implements Sink { + + public static final Cache<String, String> AUTH_CACHE = CacheBuilder.newBuilder() + .initialCapacity(12) + .maximumSize(10) + .concurrencyLevel(5) + .expireAfterWrite(20, TimeUnit.MINUTES) + .build(); + + public static final String ACCESS_TOKEN_CACHE_KEY = "access_token"; + + private DingDingSinkConfig sinkConfig; + + private com.aliyun.dingtalkrobot_1_0.Client sendMessageClient; + + private com.aliyun.dingtalkoauth2_1_0.Client authClient; + + private volatile boolean isRunning = false; + + @Override + public Class<? extends Config> configClass() { + return DingDingSinkConfig.class; + } + + @Override + public void init(Config config) throws Exception { + // init config for dingding sink connector + this.sinkConfig = (DingDingSinkConfig) config; + sendMessageClient = createSendMessageClient(); + authClient = createOAuthClient(); + } + + @Override + public void init(ConnectorContext connectorContext) throws Exception { + // init config for dingding source connector + SinkConnectorContext sinkConnectorContext = (SinkConnectorContext) connectorContext; + this.sinkConfig = (DingDingSinkConfig) sinkConnectorContext.getSinkConfig(); + sendMessageClient = createSendMessageClient(); + authClient = createOAuthClient(); + } + + @Override + public void start() { + isRunning = true; + } + + @Override + public void commit(ConnectRecord record) { + + } + + @Override + public String name() { + return this.sinkConfig.getSinkConnectorConfig().getConnectorName(); + } + + @Override + public void stop() { + isRunning = false; + } + + public boolean isRunning() { + return isRunning; + } + + @SneakyThrows + @Override + public void put(List<ConnectRecord> sinkRecords) { Review Comment: In this sink, I did not see the configuration of the EventMesh runtime, so I am a bit confused where does the sink obtain data? 在该sink中,并没有看到EventMesh runtime的配置,所以我有点困惑该sink从哪里获取数据? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
