|
@@ -1,24 +1,21 @@
|
|
|
package com.alibaba.otter.canal.kafka;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Properties;
|
|
|
-import java.util.concurrent.Future;
|
|
|
|
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
|
|
import org.apache.kafka.clients.producer.Producer;
|
|
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
|
|
-import org.apache.kafka.clients.producer.RecordMetadata;
|
|
|
import org.apache.kafka.common.serialization.StringSerializer;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.alibaba.otter.canal.common.MQProperties;
|
|
|
import com.alibaba.otter.canal.protocol.FlatMessage;
|
|
|
import com.alibaba.otter.canal.protocol.Message;
|
|
|
-import com.alibaba.otter.canal.spi.CanalMQProducer;;
|
|
|
+import com.alibaba.otter.canal.spi.CanalMQProducer;
|
|
|
|
|
|
/**
|
|
|
* kafka producer 主操作类
|
|
@@ -104,8 +101,10 @@ public class CanalKafkaProducer implements CanalMQProducer {
|
|
|
for (FlatMessage flatMessage : flatMessages) {
|
|
|
if (canalDestination.getPartition() != null) {
|
|
|
try {
|
|
|
- ProducerRecord<String, String> record = new ProducerRecord<String, String>(canalDestination
|
|
|
- .getTopic(), canalDestination.getPartition(), null, JSON.toJSONString(flatMessage));
|
|
|
+ ProducerRecord<String, String> record = new ProducerRecord<String, String>(canalDestination.getTopic(),
|
|
|
+ canalDestination.getPartition(),
|
|
|
+ null,
|
|
|
+ JSON.toJSONString(flatMessage));
|
|
|
producer2.send(record);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
@@ -123,8 +122,7 @@ public class CanalKafkaProducer implements CanalMQProducer {
|
|
|
FlatMessage flatMessagePart = partitionFlatMessage[i];
|
|
|
if (flatMessagePart != null) {
|
|
|
try {
|
|
|
- ProducerRecord<String, String> record = new ProducerRecord<String, String>(
|
|
|
- canalDestination.getTopic(),
|
|
|
+ ProducerRecord<String, String> record = new ProducerRecord<String, String>(canalDestination.getTopic(),
|
|
|
i,
|
|
|
null,
|
|
|
JSON.toJSONString(flatMessagePart));
|
|
@@ -138,8 +136,7 @@ public class CanalKafkaProducer implements CanalMQProducer {
|
|
|
}
|
|
|
} else {
|
|
|
try {
|
|
|
- ProducerRecord<String, String> record = new ProducerRecord<String, String>(
|
|
|
- canalDestination.getTopic(),
|
|
|
+ ProducerRecord<String, String> record = new ProducerRecord<String, String>(canalDestination.getTopic(),
|
|
|
0,
|
|
|
null,
|
|
|
JSON.toJSONString(flatMessage, SerializerFeature.WriteMapNullValue));
|