mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
增加对message的验证,过滤transaction begin end 类型
This commit is contained in:
@@ -27,11 +27,11 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Kafka -->
|
<!-- Kafka -->
|
||||||
<dependency>
|
<!--<dependency>-->
|
||||||
<groupId>org.apache.kafka</groupId>
|
<!--<groupId>org.apache.kafka</groupId>-->
|
||||||
<artifactId>kafka-clients</artifactId>
|
<!--<artifactId>kafka-clients</artifactId>-->
|
||||||
<version>0.10.0.1</version>
|
<!--<version>0.10.0.1</version>-->
|
||||||
</dependency>
|
<!--</dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.kafka</groupId>
|
<groupId>org.apache.kafka</groupId>
|
||||||
<artifactId>kafka_2.11</artifactId>
|
<artifactId>kafka_2.11</artifactId>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.apache.kafka.common.serialization.StringSerializer;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,10 +48,20 @@ public class CanalKafkaProducer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void send(Topic topic, Message message) {
|
public void send(Topic topic, Message message) {
|
||||||
if (message == null || message.getEntries().isEmpty()) {
|
boolean valid = false;
|
||||||
|
if (message != null && !message.getEntries().isEmpty()) {
|
||||||
|
for (CanalEntry.Entry entry : message.getEntries()) {
|
||||||
|
if (entry.getEntryType() != CanalEntry.EntryType.TRANSACTIONBEGIN && entry.getEntryType() != CanalEntry.EntryType.TRANSACTIONEND) {
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ProducerRecord<String, Message> record;
|
ProducerRecord<String, Message> record;
|
||||||
if (topic.getPartition() != null) {
|
if (topic.getPartition() != null) {
|
||||||
record = new ProducerRecord<String, Message>(topic.getTopic(), topic.getPartition(), null, message);
|
record = new ProducerRecord<String, Message>(topic.getTopic(), topic.getPartition(), null, message);
|
||||||
|
|||||||
Reference in New Issue
Block a user