hhuang1231 commented on code in PR #4569:
URL: https://github.com/apache/eventmesh/pull/4569#discussion_r1398588456
##########
eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/SourceWorker.java:
##########
@@ -233,16 +233,32 @@ private void startConnector() throws Exception {
}
private CloudEvent convertRecordToEvent(ConnectRecord connectRecord) {
+ CloudEventBuilder cloudEventBuilder = CloudEventBuilder.v1();
+
+ cloudEventBuilder.withId(UUID.randomUUID().toString())
+ .withSubject(config.getPubSubConfig().getSubject())
+ .withSource(URI.create("/"))
+ .withDataContentType("application/cloudevents+json")
+ .withType(CLOUD_EVENTS_PROTOCOL_NAME)
+
.withData(Objects.requireNonNull(JsonUtils.toJSONString(connectRecord.getData())).getBytes(StandardCharsets.UTF_8))
+ .withExtension("ttl", 10000);
+
+ for (String key : connectRecord.getExtensions().keySet()) {
+ Object extension = connectRecord.getExtensionObj(key);
+ if (extension instanceof Integer ||
+ extension instanceof Long ||
+ extension instanceof Short ||
+ extension instanceof Byte ||
+ extension instanceof Boolean ||
+ extension instanceof Float ||
+ extension instanceof Double ||
+ extension instanceof Character ||
+ extension instanceof String) {
+ cloudEventBuilder.withExtension(key,
String.valueOf(extension));
Review Comment:
1. Adding objects in the extension was added when the connection is expanded
later. While I found that the main purpose of the addition was to support
callbacks in the source connector, it was not actually intended to send this
extension to runtime. This is an idea that I don't particularly understand, and
I wish you could tell me more details.
2. KeyValue support cannot be commanded yet Method parameters in
CloudEventBuilder#withExtension, such as Boolean, byte[], Number,
OffserDateTime, String, URI, so that the extension of ConnectRecord is fully
compatible with CloudEvent?
3. Yes, numbers can be used to simplify the judgment process.
1. 在extension中添加Object应该是后来扩展connects时新增的,原本并不支持。而我发现新增这个的主要目的是支持source
connector中的回调,它实际上并没有打算将这个extension发送至runtim。
这一块我还不是特别了解您的想法,希望可以告诉我更多的细节。
2. 那么是不是可以令KeyValue支持
CloudEventBuilder#withExtension中的方法形参,例如Boolean,byte[],Number,OffserDateTime,String,URI,从而让ConnectRecord的扩展完全兼容CloudEvent?
3. 是的,可以利用Number简化判断过程。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]