I'm using the Kafka-Net nuget package to do a basic POC for Kafka producing and consuming.
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). Is this because the Kafka-Net package hasn't been updated to support the way timestamps are handled in newer versions of Kafka? Do I need to switch to using 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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.