[英]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.