简体   繁体   English

Kafka Stream - 只有一个实例从分区读取

[英]Kafka Stream - only one instance reads from partitions

I'm trying to start 2 instances of my application to read messages from the same topic with 30 partitions, but only the first instance I start reads the messages (from all 30 partitions).我正在尝试启动我的应用程序的 2 个实例以读取来自具有 30 个分区的同一主题的消息,但只有我开始的第一个实例读取消息(来自所有 30 个分区)。

Both instances have the same configuration:两个实例具有相同的配置:

private Properties streamConfig() {
    streamConfig = new Properties();
    streamConfig.setProperty(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    streamConfig.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, "myApp");
    streamConfig.put(StreamsConfig.NUM_STREAM_THREADS_CONFIG, 30);
    streamConfig.put(StreamsConfig.REPLICATION_FACTOR_CONFIG, 3);
    streamConfig.setProperty(StreamsConfig.producerPrefix(ProducerConfig.ACKS_CONFIG), "all");
    return streamConfig;
}

What am I doing wrong?我究竟做错了什么?

Thanks.谢谢。

Try to set lower NUM_STREAM_THREADS_CONFIG.尝试设置较低的 NUM_STREAM_THREADS_CONFIG。 Each thread is actually a separate consumer.每个线程实际上是一个单独的消费者。 So what might be happening is first instance getting all partitions assigned to it.所以可能发生的事情是首先获得分配给它的所有分区。 When second instance starts rebalance happening but it not necessarily splits partitions evenly between instances (or even assigns something to second instance).当第二个实例开始重新平衡时,它不一定会在实例之间平均分割分区(或者甚至为第二个实例分配一些东西)。 In any case in setup you described 30 threads will be running idle when both instances are up.在任何情况下,您描述的设置中,当两个实例都启动时,将有 30 个线程处于空闲状态。

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

相关问题 在Kafka中,是否可以从一个主题复制选择性分区? - In Kafka, Is it possible to have replication for selective partitions from one topic? 无法从所有分区获得 Kafka 滞后 - Unable to get Kafka lag from all partitions Spring Stream Kafka重新读取所有消息 - Spring Stream Kafka re-reads all messages spring integration kafka listener线程在concurrency = partition count时读取多个partition - spring integration kafka listener thread reads multiple partitions when concurrency = partition count 来自一个 Kafka 主题源的并发 Spark stream 作业 - Concurrent Spark stream job from one Kafka topic source 卡夫卡流应用程序从写入中分开读取 - Kafka streams app seperate reads from writes ObjectOutputStream仅读取赋予它的第一个实例(java)? - ObjectOutputStream reads only the first instance given to it (java)? spring cloud stream kafka binder 以编程方式将 kafka 主题(多个分区)偏移量重置为任意数字 - spring cloud stream kafka binder resetting a kafka topic(multiple partitions) offset to an arbitrary number programatically 如果限制,如何在kafka的其余分区上应用循环 - How to apply round robin on remaining partitions in kafka if one is restricted Kafka Consumer仅在产生“足够”的数据后读取 - Kafka Consumer only reads after 'enough' data has been produced
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM