簡體   English   中英

Kafka-Net中產生的消息中沒有時間戳

[英]No timestamp in produced messages in Kafka-Net

我正在使用Kafka-Net nuget軟件包為Kafka的生產和消費做一個基本的POC。

但是,我的問題是它發布到該主題的消息似乎沒有任何時間戳(在Kafka Tool最新版本中查看)。 這是因為尚未更新Kafka-Net軟件包以支持在較新版本的Kafka中處理時間戳的方式嗎? 我需要切換到使用Confluent Kafka嗎?

消息將以正確的偏移量和有效負載附加到主題,它們的時間戳記為空。

這是我的代碼

using System;
using System.Collections.Generic;
using System.Configuration;
using KafkaNet;
using KafkaNet.Model;
using KafkaNet.Protocol;

namespace KafkaProducer
{
    class Program
    {
        static void Main(string[] args)
        {
            var brokerUri = ConfigurationManager.AppSettings["BrokerUri"];

            Console.WriteLine("Enter the topic name to publish to");
            var topicName = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine($"Now publishing to topic {topicName}, enter messages separated by a carriage return");
            Console.WriteLine();

            var uri = new Uri(brokerUri);
            var options = new KafkaOptions(uri);
            var router = new BrokerRouter(options);
            var client = new Producer(router);

            while (true)
            {
                var payload = Console.ReadLine();
                if (payload == "exit") break;
                var msg = new Message(payload);                
                client.SendMessageAsync(topicName, new List<Message> { msg }).GetAwaiter().GetResult();
            }
        }
    }
}

在Kafka中,使用屬性message.timestamp.type [CreateTime,LogAppendTime]提供消息中的時間戳,可以在生產者級別或主題級別設置該屬性。

消費者在看到消息時將看到消息時間戳。

如果要在生產者級別設置此屬性,則需要在Kafka-net API中進行檢查。

https://kafka.apache.org/documentation/#topicconfigs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM