github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/examples/java/README.md (about) 1 # How to use 2 3 The following code shows how to parse ticdc data([ticdc open protocol](https://docs.pingcap.com/tidb/stable/ticdc-open-protocol)) which consumed from kafka. 4 5 ``` 6 TicdcEventFilter filter = new TicdcEventFilter(); 7 for (KafkaMessage kafkaMessage : kafkaMessages) { 8 TicdcEventDecoder ticdcEventDecoder = new TicdcEventDecoder(kafkaMessage); 9 while (ticdcEventDecoder.hasNext()) { 10 TicdcEventData data = ticdcEventDecoder.next(); 11 if (data.getTicdcEventValue() instanceof TicdcEventRowChange) { 12 boolean ok = filter.check(data.getTicdcEventKey().getTbl(), data.getTicdcEventValue().getKafkaPartition(), data.getTicdcEventKey().getTs()); 13 if (ok) { 14 // deal with row change event 15 } else { 16 // ignore duplicated messages 17 } 18 } else if (data.getTicdcEventValue() instanceof TicdcEventDDL) { 19 // deal with ddl event 20 } else if (data.getTicdcEventValue() instanceof TicdcEventResolve) { 21 filter.resolveEvent(data.getTicdcEventValue().getKafkaPartition(), data.getTicdcEventKey().getTs()); 22 // deal with resolve event 23 } 24 System.out.println(JSON.toJSONString(data, true)); 25 } 26 } 27 28 ``` 29 [See com.pingcap.ticdc.cdc.TicdcEventDecoderTest.](src/test/java/com/pingcap/tiflow/cdc/TicdcEventDecoderTest.java). 30 31 # How to install 32 Prerequisites for building: 33 34 * Git 35 * Maven (we recommend version 3.2.5) 36 * Java 8 37 38 ``` 39 git clone git@github.com:pingcap/tiflow.git 40 cd ticdc/examples/java 41 mvn install 42 ``` 43 44 Now ticdc-decoder is installed. To add a dependency : 45 46 ```xml 47 <dependency> 48 <groupId>com.pingcap.ticdc.cdc</groupId> 49 <artifactId>ticdc-decoder</artifactId> 50 <version>4.0.6-SNAPSHOT</version> 51 </dependency> 52 ```