'How to check in C # that a message sent by a producer has successfully reached the Kafka server?
I can't find a way to confirm that a message sent to the Kafka server has been received correctly by the server. I need a confirmation that the message was sent and received correctly in order to act on the C # code in case the message was not received by the server. I have read that there is a property called ack to configure that, but I can't find how to receive such confirmation.
Solution 1:[1]
You'd use a DeliveryReport handler
Refer documentation - https://docs.confluent.io/clients-confluent-kafka-dotnet/current/overview.html
Async
var t = producer.ProduceAsync("topic", new Message<Null, string> { Value="hello world" });
t.ContinueWith(task => {
if (task.IsFaulted)
{
...
}
else
{
...
Console.WriteLine($"Wrote to offset: {task.Result.Offset}");
}
});
Synchronous
public static void handler(DeliveryReport<Null, string>)
{
...
}
public static process(...)
{
...
producer.Produce(
"my-topic", new Message<Null, string> { Value = "hello world" }, handler);
}
Solution 2:[2]
This worked for me:
bool messagePublished = false;
var result = await _producer.ProduceAsync(yourTopic, yourMessage);
if (result.Status == PersistenceStatus.Persisted)
messagePublished = true;
Notice that you have multiple PersistenceStatus values.
You can find more info on the official confluent documentation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OneCricketeer |
| Solution 2 |
