繁体   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