use of com.jeesuite.kafka.producer.handler.ProducerEventHandler in project jeesuite-libs by vakinge.
the class DefaultTopicProducer method doSyncSend.
private boolean doSyncSend(String topicName, String messageKey, DefaultMessage message) {
try {
Future<RecordMetadata> future = kafkaProducer.send(new ProducerRecord<String, Object>(topicName, messageKey, message.sendBodyOnly() ? message.getBody() : message));
RecordMetadata metadata = future.get();
for (ProducerEventHandler handler : eventHanlders) {
try {
handler.onSuccessed(topicName, metadata);
} catch (Exception e) {
}
}
if (log.isDebugEnabled()) {
log.debug("kafka_send_success,topic=" + topicName + ", messageId=" + messageKey + ", partition=" + metadata.partition() + ", offset=" + metadata.offset());
}
return true;
} catch (Exception ex) {
log.error("kafka_send_fail,topic=" + topicName + ",messageId=" + messageKey, ex);
// 同步发送直接抛异常
throw new RuntimeException(ex);
}
}
Aggregations