-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE#4412] Add WeCom sink connector. (#4558)
* Add WeCom sink connector. * Refactor: use robot webhook instead of app notification. * fix: Add test resources. * fix: code review * fix code review
- Loading branch information
1 parent
5a8cd37
commit ad4ecf3
Showing
17 changed files
with
663 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
eventmesh-connectors/eventmesh-connector-wecom/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.google.guava:guava' | ||
implementation "io.netty:netty-all" | ||
implementation 'org.apache.httpcomponents:httpclient' | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
|
||
testImplementation "org.mockito:mockito-core" | ||
testImplementation "org.mockito:mockito-junit-jupiter" | ||
testImplementation "org.mockito:mockito-inline" | ||
} |
30 changes: 30 additions & 0 deletions
30
...m/src/main/java/org/apache/eventmesh/connector/wecom/config/WeComConnectServerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.wecom.config; | ||
|
||
import org.apache.eventmesh.openconnect.api.config.Config; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class WeComConnectServerConfig extends Config { | ||
|
||
private boolean sinkEnable; | ||
} |
43 changes: 43 additions & 0 deletions
43
...m/src/main/java/org/apache/eventmesh/connector/wecom/config/WeComMessageTemplateType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.wecom.config; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum WeComMessageTemplateType { | ||
|
||
PLAIN_TEXT("text"), | ||
MARKDOWN("markdown"); | ||
|
||
private final String templateKey; | ||
|
||
WeComMessageTemplateType(String templateKey) { | ||
this.templateKey = templateKey; | ||
} | ||
|
||
public String getTemplateKey() { | ||
return templateKey; | ||
} | ||
|
||
public static WeComMessageTemplateType of(String templateKey) { | ||
return Arrays.stream(values()) | ||
.filter(v -> v.getTemplateKey().equals(templateKey)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("TemplateKey: " + templateKey + " not found.")); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../main/java/org/apache/eventmesh/connector/wecom/constants/ConnectRecordExtensionKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.wecom.constants; | ||
|
||
/** | ||
* Constants of record extension key. | ||
*/ | ||
public interface ConnectRecordExtensionKeys { | ||
|
||
String WECOM_MESSAGE_TEMPLATE_TYPE_KEY = "weCom:MessageTemplateTypeKey"; | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...r-wecom/src/main/java/org/apache/eventmesh/connector/wecom/server/WeComConnectServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.wecom.server; | ||
|
||
import org.apache.eventmesh.common.Constants; | ||
import org.apache.eventmesh.connector.wecom.config.WeComConnectServerConfig; | ||
import org.apache.eventmesh.connector.wecom.sink.connector.WeComSinkConnector; | ||
import org.apache.eventmesh.openconnect.Application; | ||
import org.apache.eventmesh.openconnect.util.ConfigUtil; | ||
|
||
public class WeComConnectServer { | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
WeComConnectServerConfig weComConnectServerConfig = ConfigUtil.parse(WeComConnectServerConfig.class, | ||
Constants.CONNECT_SERVER_CONFIG_FILE_NAME); | ||
|
||
if (weComConnectServerConfig.isSinkEnable()) { | ||
Application application = new Application(); | ||
application.run(WeComSinkConnector.class); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...m/src/main/java/org/apache/eventmesh/connector/wecom/sink/config/SinkConnectorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.wecom.sink.config; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SinkConnectorConfig { | ||
|
||
private String connectorName; | ||
|
||
private String robotWebhookKey; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...wecom/src/main/java/org/apache/eventmesh/connector/wecom/sink/config/WeComSinkConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.wecom.sink.config; | ||
|
||
import org.apache.eventmesh.openconnect.api.config.SinkConfig; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
public class WeComSinkConfig extends SinkConfig { | ||
|
||
private SinkConnectorConfig sinkConnectorConfig; | ||
} |
39 changes: 39 additions & 0 deletions
39
...src/main/java/org/apache/eventmesh/connector/wecom/sink/connector/SendMessageRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.wecom.sink.connector; | ||
|
||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
|
||
@Data | ||
@Accessors(chain = true) | ||
public class SendMessageRequest { | ||
|
||
@JsonProperty("msgtype") | ||
private String messageType; | ||
|
||
@JsonProperty("text") | ||
private Map<String, Object> textContent; | ||
|
||
@JsonProperty("markdown") | ||
private Map<String, Object> markdownContent; | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/org/apache/eventmesh/connector/wecom/sink/connector/SendMessageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.wecom.sink.connector; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SendMessageResponse { | ||
|
||
@JsonProperty("errcode") | ||
private int errorCode; | ||
|
||
@JsonProperty("errmsg") | ||
private String errorMessage; | ||
} |
Oops, something went wrong.