Custom Message Parsing
Overview
If a message broker such as Kafka carries messages in a format specific to your application, use custom code to extract the database or schema, table, columns, and field values. BladePipe incrementally syncs the resulting records to the target database.
A single message can produce multiple rows. The parser can route those rows to different target databases and tables.
Supported Source and Target
| Source | Target |
|---|---|
| Kafka | IoTDB 1.x (Tree model) |
Procedure
Write the Parser
-
Import the cloudcanal-data-process project into your IDE. Use KafkaJsonArrayToIoTDB.java in the
data-transformmodule as a reference. -
Implement the
processmethod ofCcMqOriginMsgProcessorV2. Read the raw message fromCcMqOriginMsgand group the resulting records intoCustomDataobjects by target database and table. Set the target database or schema and table inSchemaInfo, and retain the source topic. For each record, specify the column names, types, and values. -
Set the fully qualified class name in
data-transform/src/main/resources/META-INF/cloudcanal/plugin.properties. For the example, use the following value.loadClassName=com.clougence.cloudcanal.dataprocess.datatransform.KafkaJsonArrayToIoTDB
Build the JAR
-
From the
cloudcanal-data-processproject root, run the following command.mvn -pl data-transform -am clean package -
Get
data-transform-1.0.0-SNAPSHOT.jarfromdata-transform/target/. The JAR contains the parser class andplugin.properties.
Prepare the Target
Prepare the target schema so that the database or schema, table, and column names match the parser output. In IoTDB, these correspond to databases, devices, and measurements.
Create the DataJob
- Go to DataJob > Create DataJob. In the DataSource step, choose Kafka as the source and IoTDB as the target. In the source Advanced settings, set Message Format to Origin Format and Decode Message Body to do not decode.
- In the DataJob step, select Incremental. In Tables, select the Kafka topics to subscribe to.
- In Data Processing, click Upload Custom Code and upload the JAR you built.
- In Creation, review the configuration and submit the DataJob.