Skip to content

Conversation

@wizardzhang
Copy link
Contributor

@wizardzhang wizardzhang commented Dec 1, 2023

Fixes #4410.

Motivation

add new feature wechat sink connector

Modifications

add new module eventmesh-connector-wechat in eventmesh-connector

Documentation

  • Does this pull request introduce a new feature? (yes / no) yes
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@wizardzhang
Copy link
Contributor Author

@pandaapo can u reviewe this pr for me?

import java.util.List;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.Protocol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can perform a checkstyle check locally to fix this import order error, otherwise CI will report checkstyle error. You can refer to https://eventmesh.apache.org/community/contribute/contribute#code-style to help you use checkstyle plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used Apache EventMesh check style,my idea show like this ,
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many possible reasons for this, which could be Checkstyle configuration issues, Checkstyle plugin settings issues, or Checkstyle version issues. Sorry, I can't help you solve it directly.

If you are familiar with Spotless, you can execute the relevant Spotless commands in the project to automatically help you adjust code style, but it may also adjust files outside of this PR.

If none of the above is convenient for you, you can manually locate and resolve the specific errors reported by CI. I am now starting to run the CI for this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023-12-02T05:10:42.0323270Z > Task :eventmesh-connectors:eventmesh-connector-wechat:checkstyleMain
2023-12-02T05:10:42.3737160Z [ant:checkstyle] [WARN] /Users/runner/work/eventmesh/eventmesh/eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:27:1: 'okhttp3.Call' should be separated from previous imports. [ImportOrder]
2023-12-02T05:10:42.3740770Z 
2023-12-02T05:10:42.3747510Z [ant:checkstyle] [WARN] /Users/runner/work/eventmesh/eventmesh/eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:30:1: Wrong order for 'org.apache.eventmesh.connector.wechat.sink.config.WeChatSinkConfig' import. [ImportOrder]
2023-12-02T05:10:42.3751510Z > Task :eventmesh-connectors:eventmesh-connector-wechat:checkstyleTest FAILED
2023-12-02T05:10:42.3755240Z [ant:checkstyle] [WARN] /Users/runner/work/eventmesh/eventmesh/eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:35:1: 'org.junit.jupiter.api.BeforeEach' should be separated from previous imports. [ImportOrder]
2023-12-02T05:10:42.3760840Z [ant:checkstyle] [WARN] /Users/runner/work/eventmesh/eventmesh/eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:50:1: Wrong order for 'java.lang.reflect.Field' import. [ImportOrder]
2023-12-02T05:10:42.3810020Z [ant:checkstyle] [WARN] /Users/runner/work/eventmesh/eventmesh/eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:64:9: Distance between variable 'weChatSinkConfig' declaration and its first usage is 5, but allowed 3.  Consider making that variable final if you still need to store its value in advance (before method calls that might have side effects on the original value). [VariableDeclarationUsageDistance]
2023-12-02T05:10:42.4728570Z [ant:checkstyle] [WARN] /Users/runner/work/eventmesh/eventmesh/eventmesh-connectors/eventmesh-connector-wechat/src/test/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnectorTest.java:91: Line is longer than 150 characters (found 152). [LineLength]

These are checkstyle errors.

Dependencies check failed, please check if you add known dependencies
Error: Process completed with exit code 1.

You need to add com.squareup.okhttp3:okhttp:4.10.0 to eventmesh/tools/dependency-check/known-dependencies.txt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ,i find okhttp-3.14.9.jar in known-dependencies.txt, so i downgrade the version, i fix my check style setting, it is work

@Slf4j
public class WeChatSinkConnector implements Sink {

public static final Cache<String, String> ACCESS_TOKEN_CACHE = CacheBuilder.newBuilder()
Copy link
Member

@pandaapo pandaapo Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only store a pair of key-value, it seems unnecessary to use such a data structure. Is it possible to directly store access token using a regular field?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this reason #4594 (comment), Cache<String, String> type is reasonable.

}

@SneakyThrows
private String getAccessToken() {
Copy link
Member

@pandaapo pandaapo Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this method be placed in init() or start() method call? This way, there is no need to invoke this method every time a message is sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this method be placed in init() or start() method call? This way, there is no need to invoke this method every time a message is sent.

the token has expire time, when expired ,u have to get it from server again, so i cache it in local, that why use the "Cache<String, String>" structure

String accessToken = getAccessToken();
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(new String((byte[]) record.getData()), mediaType);
RequestBody body = RequestBody.create(mediaType, new String((byte[]) record.getData()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your new modification here. So I would like to confirm one thing with you. You have successfully run this Sink locally and sent messages to WeChat, right?

Copy link
Contributor Author

@wizardzhang wizardzhang Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because i downgrade the version so the RequestBody.create api is diffrent from the 4.10.0, here is the test result
image

HierarchyTraversalMode.BOTTOM_UP).get(0);
clientField.setAccessible(true);
clientField.set(weChatSinkConnector, okHttpClient);
weChatSinkConnector.start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to execute the stop() at the end of unit test, although not executing this method currently does not have any impact.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i will fix it soon

@codecov
Copy link

codecov bot commented Dec 2, 2023

Codecov Report

Attention: 46 lines in your changes are missing coverage. Please review.

Comparison is base (5998926) 16.79% compared to head (1b272cc) 16.93%.

Files Patch % Lines
...tor/wechat/sink/connector/WeChatSinkConnector.java 62.65% 25 Missing and 6 partials ⚠️
...h/connector/wechat/server/WeChatConnectServer.java 0.00% 6 Missing ⚠️
...ector/wechat/config/WeChatConnectServerConfig.java 0.00% 3 Missing ⚠️
...wechat/sink/connector/TemplateMessageResponse.java 25.00% 3 Missing ⚠️
...nector/wechat/sink/config/SinkConnectorConfig.java 50.00% 2 Missing ⚠️
...connector/wechat/sink/config/WeChatSinkConfig.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #4594      +/-   ##
============================================
+ Coverage     16.79%   16.93%   +0.13%     
- Complexity     1677     1692      +15     
============================================
  Files           782      788       +6     
  Lines         29317    29420     +103     
  Branches       2532     2539       +7     
============================================
+ Hits           4924     4981      +57     
- Misses        23933    23973      +40     
- Partials        460      466       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xwm1992 xwm1992 merged commit d463fa7 into apache:master Dec 3, 2023
@pandaapo pandaapo added this to the 1.10 milestone Dec 5, 2023
xuhongjia pushed a commit to Deckers-Ohana/eventmesh that referenced this pull request Mar 13, 2025
* add wechat connector module and dependency

* add wechat connector

* add unit test

* fix check style error and downgrade okhttp version to 3.14.9

* add stop method after test end

* fix check style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Wechat sink connector

3 participants