-
Notifications
You must be signed in to change notification settings - Fork 641
[ISSUE #4410]add wechat sink connector #4594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@pandaapo can u reviewe this pr for me? |
| import java.util.List; | ||
| import okhttp3.Call; | ||
| import okhttp3.MediaType; | ||
| import okhttp3.Protocol; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()orstart()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())); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| HierarchyTraversalMode.BOTTOM_UP).get(0); | ||
| clientField.setAccessible(true); | ||
| clientField.set(weChatSinkConnector, okHttpClient); | ||
| weChatSinkConnector.start(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ReportAttention:
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. |
* 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


Fixes #4410.
Motivation
add new feature wechat sink connector
Modifications
add new module eventmesh-connector-wechat in eventmesh-connector
Documentation