简体   繁体   English

Kafka-Net中产生的消息中没有时间戳

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

I'm using the Kafka-Net nuget package to do a basic POC for Kafka producing and consuming. 我正在使用Kafka-Net nuget软件包为Kafka的生产和消费做一个基本的POC。

The problem I have however is that the messages it publishes to the topic don't seem to have any timestamps (when viewed in Kafka Tool latest version). 但是,我的问题是它发布到该主题的消息似乎没有任何时间戳(在Kafka Tool最新版本中查看)。 Is this because the Kafka-Net package hasn't been updated to support the way timestamps are handled in newer versions of Kafka? 这是因为尚未更新Kafka-Net软件包以支持在较新版本的Kafka中处理时间戳的方式吗? Do I need to switch to using Confluent Kafka? 我需要切换到使用Confluent Kafka吗?

Messages are appended to the topic with correct offsets and payload, they just have a blank timestamp. 消息将以正确的偏移量和有效负载附加到主题,它们的时间戳记为空。

This is my code 这是我的代码

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();
            }
        }
    }
}

In Kafka,timestamp in messages are provided using property message.timestamp.type [CreateTime, LogAppendTime] which can be set at producer level or topic level. 在Kafka中,使用属性message.timestamp.type [CreateTime,LogAppendTime]提供消息中的时间戳,可以在生产者级别或主题级别设置该属性。

A consumer will see the message timestamp when it sees the messages. 消费者在看到消息时将看到消息时间戳。

If you want to set this property at producer level then you need to check at Kafka-net API. 如果要在生产者级别设置此属性,则需要在Kafka-net API中进行检查。

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM