com.soento.logback.kafka.delivery.AsynchronousDeliveryStrategy Maven / Gradle / Ivy
package com.soento.logback.kafka.delivery;
import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.errors.TimeoutException;
/**
* @since 0.0.1
*/
public class AsynchronousDeliveryStrategy implements DeliveryStrategy {
@Override
public boolean send(Producer producer, ProducerRecord record, final E event,
final FailedDeliveryCallback failedDeliveryCallback) {
try {
producer.send(record, new Callback() {
@Override
public void onCompletion(RecordMetadata metadata, Exception exception) {
if (exception != null) {
failedDeliveryCallback.onFailedDelivery(event, exception);
}
}
});
return true;
} catch (BufferExhaustedException | TimeoutException e) {
failedDeliveryCallback.onFailedDelivery(event, e);
return false;
}
}
}