public void HandleDeliveryReport(Producer.UntypedDeliveryReport deliveryReport) { if (deliveryReport == null) { return; } var dr = new DeliveryReportResult <TKey, TValue> { TopicPartitionOffsetError = deliveryReport.TopicPartitionOffsetError, Message = new Message <TKey, TValue> { Key = Key, Value = Value, Timestamp = deliveryReport.Message == null ? new Timestamp(0, TimestampType.NotAvailable) : deliveryReport.Message.Timestamp, Headers = deliveryReport.Message?.Headers } }; // topic is cached in this object, not set in the deliveryReport to avoid the // cost of marshalling it. dr.Topic = Topic; if (Handler != null) { Handler(dr); } }
public void HandleDeliveryReport(Producer.UntypedDeliveryReport deliveryReport) { if (deliveryReport == null) { #if NET45 System.Threading.Tasks.Task.Run(() => TrySetResult(null)); #else TrySetResult(null); #endif return; } var dr = new DeliveryReport <TKey, TValue> { TopicPartitionOffset = deliveryReport.TopicPartitionOffset, Message = new Message <TKey, TValue> { Key = Key, Value = Value, Timestamp = deliveryReport.Message.Timestamp, Headers = deliveryReport.Message.Headers } }; // topic is cached in this object, not set in the deliveryReport to avoid the // cost of marshalling it. dr.Topic = Topic; #if NET45 if (deliveryReport.Error.IsError) { System.Threading.Tasks.Task.Run(() => SetException(new ProduceException <TKey, TValue>(deliveryReport.Error, dr))); } else { System.Threading.Tasks.Task.Run(() => TrySetResult(dr)); } #else if (deliveryReport.Error.IsError) { TrySetException(new ProduceException <TKey, TValue>(deliveryReport.Error, dr)); } else { TrySetResult(dr); } #endif }