mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
默认将数据发现kafka的partition 0,避免多分区的数据一致性问题
后续将支持通过id hash分发数据
This commit is contained in:
@@ -75,7 +75,7 @@ public class CanalKafkaProducer {
|
||||
if (topic.getPartition() != null) {
|
||||
record = new ProducerRecord<String, Message>(topic.getTopic(), topic.getPartition(), null, message);
|
||||
} else {
|
||||
record = new ProducerRecord<String, Message>(topic.getTopic(), message);
|
||||
record = new ProducerRecord<String, Message>(topic.getTopic(), 0, null, message);
|
||||
}
|
||||
|
||||
producer.send(record);
|
||||
@@ -84,8 +84,18 @@ public class CanalKafkaProducer {
|
||||
List<FlatMessage> flatMessages = FlatMessage.messageConverter(message);
|
||||
if (flatMessages != null) {
|
||||
for (FlatMessage flatMessage : flatMessages) {
|
||||
ProducerRecord<String, String> record = new ProducerRecord<String, String>(topic.getTopic(),
|
||||
JSON.toJSONString(flatMessage));
|
||||
ProducerRecord<String, String> record;
|
||||
if (topic.getPartition() != null) {
|
||||
record = new ProducerRecord<String, String>(topic.getTopic(),
|
||||
topic.getPartition(),
|
||||
null,
|
||||
JSON.toJSONString(flatMessage));
|
||||
} else {
|
||||
record = new ProducerRecord<String, String>(topic.getTopic(),
|
||||
0,
|
||||
null,
|
||||
JSON.toJSONString(flatMessage));
|
||||
}
|
||||
producer2.send(record);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user