kafka producer - call callback.onFailure in case of producer.send exception (like InterruptedException when buffer.memory and max.block.ms reached)
This commit is contained in:
parent
2d4831af39
commit
2a4a9187d1
@ -77,6 +77,7 @@ public class TbKafkaProducerTemplate<T extends TbQueueMsg> implements TbQueuePro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(TopicPartitionInfo tpi, T msg, TbQueueCallback callback) {
|
public void send(TopicPartitionInfo tpi, T msg, TbQueueCallback callback) {
|
||||||
|
try {
|
||||||
createTopicIfNotExist(tpi);
|
createTopicIfNotExist(tpi);
|
||||||
String key = msg.getKey().toString();
|
String key = msg.getKey().toString();
|
||||||
byte[] data = msg.getData();
|
byte[] data = msg.getData();
|
||||||
@ -96,6 +97,14 @@ public class TbKafkaProducerTemplate<T extends TbQueueMsg> implements TbQueuePro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (callback != null) {
|
||||||
|
callback.onFailure(e);
|
||||||
|
} else {
|
||||||
|
log.warn("Producer template failure (send method wrapper): {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTopicIfNotExist(TopicPartitionInfo tpi) {
|
private void createTopicIfNotExist(TopicPartitionInfo tpi) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user