-
Notifications
You must be signed in to change notification settings - Fork 642
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
[ISSUE #790] Knative Connector: Initial Implementation of Producer. #1027
[ISSUE #790] Knative Connector: Initial Implementation of Producer. #1027
Conversation
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.
Welcome to the Apache EventMesh (incubating) community!!
This is your first PR in our project. We're very excited to have you onboard contributing. Your contributions are greatly appreciated!
Please make sure that the changes are covered by tests.
We will be here shortly.
Let us know if you need any help!
Want to get closer to the community?
Mailing Lists:
Name | Description | Subscribe | Unsubscribe | Archive |
---|---|---|---|---|
Users | User support and questions mailing list | Subscribe | Unsubscribe | Mail Archives |
Development | Development related discussions | Subscribe | Unsubscribe | Mail Archives |
Commits | All commits to repositories | Subscribe | Unsubscribe | Mail Archives |
@xwm1992 Please have a look when you have time. Thanks very much in advance! |
Codecov Report
@@ Coverage Diff @@
## knative-connector #1027 +/- ##
======================================================
+ Coverage 9.69% 9.87% +0.17%
- Complexity 610 629 +19
======================================================
Files 362 374 +12
Lines 23118 23244 +126
Branches 2546 2541 -5
======================================================
+ Hits 2241 2295 +54
- Misses 20675 20740 +65
- Partials 202 209 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
} | ||
|
||
@Override | ||
public void sendOneway(CloudEvent cloudEvent) { |
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.
Please not implement this method, you should impelement the publish
method with the send call back.
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.
Thanks for your comments. I will change to the publish
method instead.
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.
Implemented publish
method with SendCallback.
// Set HTTP header for CloudEvent: | ||
this.httpUrlConnection.setRequestProperty(KnativeHeaders.CONTENT_TYPE, properties.getProperty(KnativeHeaders.CONTENT_TYPE)); | ||
this.httpUrlConnection.setRequestProperty(KnativeHeaders.CE_ID, properties.getProperty(KnativeHeaders.CE_ID)); | ||
this.httpUrlConnection.setRequestProperty(KnativeHeaders.CE_SPECVERSION, properties.getProperty(KnativeHeaders.CE_SPECVERSION)); | ||
this.httpUrlConnection.setRequestProperty(KnativeHeaders.CE_TYPE, properties.getProperty(KnativeHeaders.CE_TYPE)); | ||
this.httpUrlConnection.setRequestProperty(KnativeHeaders.CE_SOURCE, properties.getProperty(KnativeHeaders.CE_SOURCE)); |
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.
These code for HTTP header attributes with the request, I recommend that you can write them when you send the cloud events not when you init the
producer`.
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.
Thanks for your comments. I will move this part out of the init
period.
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.
Moved HTTP header setting into send
method.
public void sendOneway(CloudEvent cloudEvent) { | ||
// Get CloudEvent data: | ||
try { | ||
String data = KnativeMessageFactory.createReader(cloudEvent); | ||
super.getHttpUrlConnection().getOutputStream().write(data.getBytes(StandardCharsets.UTF_8)); | ||
|
||
// Send CloudEvent message: | ||
String s = ""; | ||
int code = super.getHttpUrlConnection().getResponseCode(); | ||
if (code == 200) { | ||
BufferedReader reader = new BufferedReader( | ||
new InputStreamReader(super.getHttpUrlConnection().getInputStream())); | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
s += line + "\n"; | ||
} | ||
reader.close(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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 don't need to have this method, and when you implement the publish method with the callback, you can use the Async Http Client
, here don't implement synchronously.
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.
Thanks for your comments. I will change to the asynchronous way to call the publish
method.
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.
- Implemented
sendAsync
method by using AsyncHttpClient. - Added a simple exception checker method
checkProducerException
and a utility methodconvertSendResult
to help implement methods with SendCallback. - Added AsyncHttpClient dependency to build.gradle file.
public KnativeMessageWriter(String data) { | ||
String s = "{ \"msg\": [\"" + data + "\"]}"; | ||
this.message = new CloudEventBuilder() | ||
.withId("my-id") | ||
.withSource(URI.create("/myClient")) | ||
.withType("dev.knative.cronjob.event") | ||
.withDataContentType("application/json") | ||
.withData(s.getBytes(StandardCharsets.UTF_8)) | ||
.build(); | ||
} |
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.
These codes look strange, you use the cloudeventbuilder to build the cloud events, but you only want to put the data, other attributes are useless.
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.
Thanks for your comments. I will remove the unnecessary attributes.
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.
Removed unnecessary attributes in KnativeMessageWriter
.
1. Changed to load Knative service URL from properties file (added common/EventMeshConstants, config/ClientConfiguration, and config/ConfigurationWrapper). 2. Deleted unused sendCallbackConvert method. 3. Added exception handling for HTTP response code error in send method. 4. Added related build.gradle dependencies, tools/known-dependencies.txt dependency, and third-party-licenses/LICENSE-httpasyncclient.txt file.
1. Fixed issue in Continuous Integration / Build (ubuntu-latest, 8) (pull_request). 2. Fixed issue in Continuous Integration / Build (ubuntu-latest, 11) (pull_request). 3. Fixed issue in Continuous Integration / Build (macOS-latest, 8) (pull_request). 4. Fixed issue in Continuous Integration / Build (macOS-latest, 11) (pull_request). 5. Fixed issue in Continuous Integration / License Check (pull_request).
Fixing ISSUE #790.
Motivation
Implemented and tested Producer module to publish an event to Knative (ISSUE #790).
The PRs for ISSUE #790 will be merged into knative-connector branch.
Modifications
Followed the API design style of eventmesh-connector-api and made the following modifications.
Implementation
How to Test
Assume the cloudevents-player Knative service has already been set up on your local machine; otherwise, please follow the steps in https://knative.dev/docs/getting-started/first-source/#sending-an-event to set up a Knative service (cloudevents-player) as a sink.
Documentation