我需要我的消费者从特定的消费TopicPartitionOffset(here from offset 278)
.假设消息是由某些Producer在特定主题中生成的,就像="Test_1"
之前一样.这是我的代码
using System;
using Confluent.Kafka;
public class ConsumingTest
{
public static void Main(string[] args)
{
var consumerConfig = new ConsumerConfig
{
BootstrapServers = "localhost:9092", EnableAutoCommit = false, GroupId = "this-group-id"
};
using (var consumer = new Consumer<Null, string>(consumerConfig))
{
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Consume Started...");
consumer.Subscribe("Test_1");
var topicPartitionOffset = new TopicPartitionOffset("Test_1", new Partition(0), new Offset(278));
consumer.Assign(topicPartitionOffset);
consumer.Seek(topicPartitionOffset);
while (true)
try
{
var cr = consumer.Consume();
Console.WriteLine($"Consumed message '{cr.Value}' at: '{cr.TopicPartitionOffset}'.");
}
catch (ConsumeException e)
{
Console.WriteLine(e.Message);
} …
Run Code Online (Sandbox Code Playgroud) .net apache-kafka .net-core kafka-consumer-api confluent-kafka
我在项目中使用通用宿主模式。我需要一个记录器来专门归档Serilog之类的滚动文件。如何将其添加到主机构建器的某些记录器配置中。
在通用主机中,我们可以添加日志配置,例如调试器和控制台。但是我想使用记录器来归档特定选项。我不知道该怎么做。
最佳做法是哪种?