小编M.H*_*adi的帖子

如何使用.Net中的Confluent.Kafka从特定的TopicPartitionOffset进行消耗

我需要我的消费者从特定的消费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

9
推荐指数
1
解决办法
1260
查看次数

如何在C#中将serilog记录器添加到GenericHost项目

我在项目中使用通用宿主模式。我需要一个记录器来专门归档Serilog之类的滚动文件。如何将其添加到主机构建器的某些记录器配置中。

在通用主机中,我们可以添加日志配置,例如调试器和控制台。但是我想使用记录器来归档特定选项。我不知道该怎么做。

最佳做法是哪种?

c# serilog .net-core

5
推荐指数
3
解决办法
176
查看次数