Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Random partitioner不会在Kafka主题分区之间分发消息_C#_Apache Kafka_Confluent Platform - Fatal编程技术网

C# Random partitioner不会在Kafka主题分区之间分发消息

C# Random partitioner不会在Kafka主题分区之间分发消息,c#,apache-kafka,confluent-platform,C#,Apache Kafka,Confluent Platform,我在Kafka中创建了一个带有9个分区的主题,将其恰当地命名为“test”,并使用Confluent.Kafka客户端库(生产者和消费者)在C#(.NET核心)中组合了两个简单的应用程序。我只做了些调整 我正在运行两个消费者应用程序实例和一个生产者实例。我不认为在这里粘贴消费代码有多大意义,这是一个简单的“获取消息,在屏幕上打印”应用程序,但是,它也会打印消息来自的分区号 这是producer应用程序: static async Task Main(string[] args)

我在Kafka中创建了一个带有9个分区的主题,将其恰当地命名为“test”,并使用
Confluent.Kafka
客户端库(生产者和消费者)在C#(.NET核心)中组合了两个简单的应用程序。我只做了些调整

我正在运行两个消费者应用程序实例和一个生产者实例。我不认为在这里粘贴消费代码有多大意义,这是一个简单的“获取消息,在屏幕上打印”应用程序,但是,它也会打印消息来自的分区号

这是producer应用程序:

    static async Task Main(string[] args)
    {
        var random = new Random();

        var config = new ProducerConfig {
            BootstrapServers = "10.0.0.5:9092",
            Partitioner = Partitioner.ConsistentRandom
        };

        int counter = 0;
        while (true)
        {
            using (var p = new ProducerBuilder<string, string>(config).Build())
            {
                try
                {
                    p.BeginProduce(
                        "test",
                        new Message<string, string>
                        {
                            //Key = random.Next().ToString(),
                            Value = $"test {++counter}"
                        });

                    if (counter % 10 == 0)
                        p.Flush();
                }
                catch (ProduceException<Null, string> e)
                {
                    Console.WriteLine($"Delivery failed: {e.Error.Reason}");
                }
            }
        }
    }

我遇到了同样的问题。 似乎在启动客户机时,第一条消息总是发送到同一个分区。
如果您对所有消息使用同一个客户端,Partioner.Random将起作用

我认为项目中不会有bug。你能添加到Partitioner配置文档的链接吗?@JRibkr是的,我也不认为这是一个bug,这么明显的东西肯定会被发现。我从库中的XML文档复制了文档,正如在VisualStudio中看到的那样,我不知道是否有在线版本可用。谷歌搜索只产生了这个源文件:我遇到了同样的问题,使用
ProducerBuilder
,设置
Partitioner=Partitioner.Random
没有任何效果。所有消息都生成到单个分区@kamilk或@Ran Mansoor,你有没有可以共享的工作代码?
// Summary:
//     Partitioner: `random` - random distribution, `consistent` - CRC32 hash of key
//     (Empty and NULL keys are mapped to single partition), `consistent_random` - CRC32
//     hash of key (Empty and NULL keys are randomly partitioned), `murmur2` - Java
//     Producer compatible Murmur2 hash of key (NULL keys are mapped to single partition),
//     `murmur2_random` - Java Producer compatible Murmur2 hash of key (NULL keys are
//     randomly partitioned. This is functionally equivalent to the default partitioner
//     in the Java Producer.). default: consistent_random importance: high