odbozhou commented on code in PR #291:
URL: https://github.com/apache/rocketmq-connect/pull/291#discussion_r971579495


##########
connectors/rocketmq-connect-activemq/src/main/java/org/apache/rocketmq/connect/activemq/connector/ActivemqSourceTask.java:
##########
@@ -131,11 +118,52 @@ public ByteBuffer getMessageContent(Message message) 
throws JMSException {
             while ((i = streamMessage.readBytes(by)) != -1) {
                 bis.write(by, 0, i);
             }
-            data = bis.toByteArray();
+            data = bis.toString();
         } else {
             // The exception is printed and does not need to be written as a 
DataConnectException
             throw new RuntimeException("message type exception");
         }
-        return ByteBuffer.wrap(data);
+        return data;
+    }
+
+    private ConnectRecord message2ConnectRecord(Message message) throws 
JMSException {
+        Schema schema = SchemaBuilder.struct().name("activemq").build();
+        final List<Field> fields = buildFields();
+        schema.setFields(fields);
+        return new ConnectRecord(buildRecordPartition(),
+            buildRecordOffset(),
+            System.currentTimeMillis(),
+            schema,
+            buildPayLoad(fields, message, schema));
+    }
+
+    private RecordOffset buildRecordOffset()  {
+        Map<String, Long> offsetMap = new HashMap<>();
+        RecordOffset recordOffset = new RecordOffset(offsetMap);

Review Comment:
   RecordOffset value is empty map?



##########
connectors/rocketmq-connect-activemq/src/main/java/org/apache/rocketmq/connect/activemq/connector/ActivemqSourceTask.java:
##########
@@ -131,11 +118,52 @@ public ByteBuffer getMessageContent(Message message) 
throws JMSException {
             while ((i = streamMessage.readBytes(by)) != -1) {
                 bis.write(by, 0, i);
             }
-            data = bis.toByteArray();
+            data = bis.toString();
         } else {
             // The exception is printed and does not need to be written as a 
DataConnectException
             throw new RuntimeException("message type exception");
         }
-        return ByteBuffer.wrap(data);
+        return data;
+    }
+
+    private ConnectRecord message2ConnectRecord(Message message) throws 
JMSException {
+        Schema schema = SchemaBuilder.struct().name("activemq").build();
+        final List<Field> fields = buildFields();
+        schema.setFields(fields);
+        return new ConnectRecord(buildRecordPartition(),
+            buildRecordOffset(),
+            System.currentTimeMillis(),
+            schema,
+            buildPayLoad(fields, message, schema));
+    }
+
+    private RecordOffset buildRecordOffset()  {
+        Map<String, Long> offsetMap = new HashMap<>();
+        RecordOffset recordOffset = new RecordOffset(offsetMap);
+        return recordOffset;
+    }
+
+    private RecordPartition buildRecordPartition() {
+        Map<String, String> partitionMap = new HashMap<>();
+        partitionMap.put("partition", "defaultPartition");
+        RecordPartition  recordPartition = new RecordPartition(partitionMap);
+        return recordPartition;
+    }
+
+    private List<Field> buildFields() {
+        final Schema stringSchema = SchemaBuilder.string().build();
+        List<Field> fields = new ArrayList<>();
+        fields.add(new Field(0, Config.DESTINATION_NAME, stringSchema));
+        fields.add(new Field(1, Config.DESTINATION_TYPE, stringSchema));
+        fields.add(new Field(2, Config.MESSAGE, stringSchema));
+        return fields;
+    }
+
+    private Struct buildPayLoad(List<Field> fields, Message message, Schema 
schema) throws JMSException {
+        Struct payLoad = new Struct(schema);
+        payLoad.put(fields.get(0), config.getDestinationName());
+        payLoad.put(fields.get(1), config.getDestinationType());
+        payLoad.put(fields.get(2), getMessageContent(message));

Review Comment:
   Whether the payload can only put the message data, the extra information can 
be put in the extension field, it will be more general



-- 
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]

Reply via email to