pandaapo commented on code in PR #4569:
URL: https://github.com/apache/eventmesh/pull/4569#discussion_r1398703518
##########
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:
> So can I assume that now I need ConnectRecord to be compatible with
CloudEvent, and at the same time I will retain the storage and acquisition of
Object in ConnectRecord.
If `ConnectRecord` and `KeyValue` can support all parameter types of
`CloudEvent#withExtension()`, the storage and retrieval of Object can be
preserved or not. If it is not preserved, what I can think of is using generics
to receive multiple data types. Looking forward to your solution.
如果能做到`ConnectRecord`和`KeyValue`能支持`CloudEvent#withExtension()`的全部参数类型,保不保留Object的存放和获取都可以。如果不保留,我能想到的是用泛型来接收多种数据类型,期待您的方案。
> The former is mainly used to send events to the runtime, and the latter is
mainly used for some special purposes of the source/sink itself?
Yes. `CloudEvent` is sent to runtime, and `ConnectorRecord` is used by
source/sink.
是的,`CloudEvent`发给runtime,`ConnectorRecord`由source/sink使用。
##########
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:
> So can I assume that now I need ConnectRecord to be compatible with
CloudEvent, and at the same time I will retain the storage and acquisition of
Object in ConnectRecord.
If `ConnectRecord` and `KeyValue` can support all parameter types of
`CloudEvent#withExtension()`, the storage and retrieval of Object can be
preserved or not. If it is not preserved, what I can think of is using generics
to receive multiple data types. Looking forward to your solution.
如果能做到`ConnectRecord`和`KeyValue`能支持`CloudEvent#withExtension()`的全部参数类型,保不保留Object的存放和获取都可以。如果不保留,我能想到的是用泛型来接收多种数据类型,期待您的方案。
> The former is mainly used to send events to the runtime, and the latter is
mainly used for some special purposes of the source/sink itself?
Yes. `CloudEvent` is sent to runtime, and `ConnectorRecord` is used by
source/sink.
是的,`CloudEvent`发给runtime,`ConnectorRecord`由source/sink使用。
--
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]