简体   繁体   English

如何在 C# 中检查生产者发送的消息是否已成功到达 Kafka 服务器?

[英]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.我找不到确认发送到 Kafka 服务器的消息是否已被服务器正确接收的方法。 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.我需要确认消息已正确发送和接收,以便在服务器未收到消息的情况下对 C# 代码执行操作。 I have read that there is a property called ack to configure that, but I can't find how to receive such confirmation.我读过有一个名为 ack 的属性来配置它,但我找不到如何接收这样的确认。

You'd use a DeliveryReport handler您将使用 DeliveryReport 处理程序

Refer documentation - https://docs.confluent.io/clients-confluent-kafka-dotnet/current/overview.html参考文档 - 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);
}

This worked for me:这对我有用:

bool messagePublished;
var result = await _producer.ProduceAsync(yourTopic, yourMessage);

if (result.Status == PersistenceStatus.Persisted)
    messagePublished = true;

Notice that you have multiple PersistenceStatus values.请注意,您有多个PersistenceStatus值。

You can find more info on the official confluent documentation .您可以在官方confluent 文档中找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查邮件是否已成功发送 - How to check if the mail has been sent successfully 使用 C# 向生产者发送消息时,如何在 kafka 消息中添加 header 属性? - How to add header properties in kafka message while sending message to producer using C#? c#udp检查消息是否到达 - c# udp check if message reached 如何使用Kerberos在C#中配置kafka生产者 - How to configurate kafka producer in C# with Kerberos 如何检查电子邮件是否已成功发送? - How to check if the email have sent successfully or not? 在 confluent-dotnet-kafka 如何在 Message Producer in.Net 中传递 object - In confluent-dotnet-kafka how to pass an object in Message Producer in .Net 如何检查.Post是否已在Facebook C#sdk中成功发送? - How do I check if .Post has send successfully in Facebook C# sdk? 我无法以Cfka生产者身份使用SSL(TLS)发布JSON消息 - I'm not able to publish JSON message with SSL(TLS) as kafka producer from C# 具有 MassTransit 的 Kafka Producer - IBusInstance 尚未注册 - Kafka Producer with MassTransit - IBusInstance has not been registered 如何检查UI元素是否已到达Windows Phone中的页面顶部 - How to check if an UI Element has reached the top of the page in windows phone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM