Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复rocketmq&kafka 发送消息失败时回滚后继续提交的问题 #1104

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.alibaba.otter.canal.kafka;

import java.util.List;
import java.util.Properties;

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 org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
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 java.util.List;
import java.util.Properties;

/**
* kafka producer 主操作类
Expand Down Expand Up @@ -93,6 +92,7 @@ record = new ProducerRecord<String, Message>(canalDestination.getTopic(), 0, nul
logger.error(e.getMessage(), e);
// producer.abortTransaction();
callback.rollback();
return;
}
} else {
// 发送扁平数据json
Expand All @@ -110,6 +110,7 @@ record = new ProducerRecord<String, Message>(canalDestination.getTopic(), 0, nul
logger.error(e.getMessage(), e);
// producer.abortTransaction();
callback.rollback();
return;
}
} else {
if (canalDestination.getPartitionHash() != null
Expand All @@ -131,6 +132,7 @@ record = new ProducerRecord<String, Message>(canalDestination.getTopic(), 0, nul
logger.error(e.getMessage(), e);
// producer.abortTransaction();
callback.rollback();
return;
}
}
}
Expand All @@ -145,6 +147,7 @@ record = new ProducerRecord<String, Message>(canalDestination.getTopic(), 0, nul
logger.error(e.getMessage(), e);
// producer.abortTransaction();
callback.rollback();
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.alibaba.otter.canal.rocketmq;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.otter.canal.common.CanalMessageSerializer;
import com.alibaba.otter.canal.common.MQProperties;
import com.alibaba.otter.canal.protocol.FlatMessage;
import com.alibaba.otter.canal.server.exception.CanalServerException;
import com.alibaba.otter.canal.spi.CanalMQProducer;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
Expand All @@ -12,12 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.otter.canal.common.CanalMessageSerializer;
import com.alibaba.otter.canal.common.MQProperties;
import com.alibaba.otter.canal.protocol.FlatMessage;
import com.alibaba.otter.canal.server.exception.CanalServerException;
import com.alibaba.otter.canal.spi.CanalMQProducer;
import java.util.List;

public class CanalRocketMQProducer implements CanalMQProducer {

Expand Down Expand Up @@ -67,6 +66,7 @@ public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
logger.error("Send message error!", e);
callback.rollback();
return;
}
} else {
List<FlatMessage> flatMessages = FlatMessage.messageConverter(data);
Expand All @@ -90,6 +90,7 @@ public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
} catch (Exception e) {
logger.error("send flat message to fixed partition error", e);
callback.rollback();
return;
}
} else {
if (destination.getPartitionHash() != null && !destination.getPartitionHash().isEmpty()) {
Expand Down Expand Up @@ -124,6 +125,7 @@ public MessageQueue select(List<MessageQueue> mqs, Message msg,
} catch (Exception e) {
logger.error("send flat message to hashed partition error", e);
callback.rollback();
return;
}
}
}
Expand Down