Skip to content

Commit

Permalink
[ISSUE apache#4411] Add DingDing sink connnector. (apache#4557)
Browse files Browse the repository at this point in the history
* Add dingding sink connector.

* fix: Remove unused config.

* fix: Remove unused config.

* fix: review

* Add example config.

* fix: review

* fix: continue when record data is null.
  • Loading branch information
yanrongzhen authored Nov 16, 2023
1 parent 709b211 commit fc900e5
Show file tree
Hide file tree
Showing 14 changed files with 647 additions and 1 deletion.
36 changes: 36 additions & 0 deletions eventmesh-connectors/eventmesh-connector-dingding/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*/

configurations {
implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
implementation.exclude group: 'log4j', module: 'log4j'
testImplementation.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}

dependencies {
implementation project(":eventmesh-common")
implementation project(":eventmesh-sdks:eventmesh-sdk-java")
implementation project(":eventmesh-openconnect:eventmesh-openconnect-java")
implementation "com.aliyun:dingtalk:2.0.61"
implementation 'com.google.guava:guava'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation "org.mockito:mockito-core"
testImplementation "org.mockito:mockito-junit-jupiter"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.common.constants;

/**
* Constants of record extension key.
*/
public interface ConnectRecordExtensionKeys {

String DINGDING_TEMPLATE_TYPE_KEY = "dingDingTemplateTypeKey";

String DINGDING_MARKDOWN_MESSAGE_TITLE = "dingDingMarkdownMessageTitle";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.config;

import org.apache.eventmesh.openconnect.api.config.Config;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class DingDingConnectServerConfig extends Config {

private boolean sinkEnable;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.config;

import java.util.Arrays;

public enum DingDingMessageTemplateType {

PLAIN_TEXT("sampleText"),
MARKDOWN("sampleMarkdown");

private final String templateKey;

DingDingMessageTemplateType(String templateKey) {
this.templateKey = templateKey;
}

public String getTemplateKey() {
return templateKey;
}

public static DingDingMessageTemplateType of(String templateKey) {
return Arrays.stream(values())
.filter(v -> v.getTemplateKey().equals(templateKey))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("TemplateKey: " + templateKey + " not found."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.server;

import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.connector.dingding.config.DingDingConnectServerConfig;
import org.apache.eventmesh.connector.dingding.sink.connector.DingDingSinkConnector;
import org.apache.eventmesh.openconnect.Application;
import org.apache.eventmesh.openconnect.util.ConfigUtil;

public class DingDingConnectServer {

public static void main(String[] args) throws Exception {

DingDingConnectServerConfig dingDingConnectServerConfig = ConfigUtil.parse(DingDingConnectServerConfig.class,
Constants.CONNECT_SERVER_CONFIG_FILE_NAME);

if (dingDingConnectServerConfig.isSinkEnable()) {
Application application = new Application();
application.run(DingDingSinkConnector.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.config;

import org.apache.eventmesh.openconnect.api.config.SinkConfig;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class DingDingSinkConfig extends SinkConfig {

private SinkConnectorConfig sinkConnectorConfig;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.config;

import lombok.Data;

@Data
public class SinkConnectorConfig {

private String connectorName;

private String appKey;

private String appSecret;

private String openConversationId;

private String robotCode;

private String coolAppCode;
}
Loading

0 comments on commit fc900e5

Please sign in to comment.