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

fix: production delivery result errors #572

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 38 additions & 8 deletions src/KafkaFlow/Producers/MessageProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,19 @@ public void Dispose()
_producer?.Dispose();
}

private static void FillContextWithResultMetadata(IMessageContext context, DeliveryResult<byte[], byte[]> result)
private void FillContextWithResultMetadata(IMessageContext context, DeliveryResult<byte[], byte[]> result)
{
var concreteProducerContext = (ProducerContext)context.ProducerContext;
var concreteProducerContext = context.ProducerContext as ProducerContext;

if (concreteProducerContext is null)
{
_logHandler.Warning("Producer context is null on FillContextWithResultMetadata", new
{
DeliveryResult = result,
});

return;
}

concreteProducerContext.Offset = result.Offset;
concreteProducerContext.Partition = result.Partition;
Expand Down Expand Up @@ -258,7 +268,17 @@ private IProducer<byte[], byte[]> EnsureProducer()
{
foreach (var handler in _configuration.StatisticsHandlers)
{
handler.Invoke(statistics);
try
{
handler?.Invoke(statistics);
}
catch (Exception ex)
{
_logHandler.Error("Kafka Producer StatisticsHandler Error", ex, new
{
ProducerName = _configuration.Name,
});
}
}
});

Expand Down Expand Up @@ -351,14 +371,24 @@ private void InternalProduce(

void Handler(DeliveryReport<byte[], byte[]> report)
{
if (report.Error.IsFatal)
try
{
this.InvalidateProducer(report.Error, report);
}
if (report.Error.IsFatal)
{
this.InvalidateProducer(report.Error, report);
}

FillContextWithResultMetadata(context, report);
FillContextWithResultMetadata(context, report);
}
catch (Exception ex)
{
_logHandler.Error("Delivery Result Handler Error", ex, new
{
Report = report,
});
}

deliveryHandler(report);
deliveryHandler?.Invoke(report);
}
}

Expand Down
Loading