简体   繁体   English

当Kafka消费者不使用订阅方法时,是否检查session.timeout.ms或max.pool.interval.ms?

[英]When Kafka consumer don't use subscribe method, do it check session.timeout.ms or max.pool.interval.ms?

this is consumer code with not using subscribe method.这是不使用订阅方法的消费者代码。

val consumer = KafkaConsumer<String, String>(properties)
val topics = listOf(TopicPartition("TEST", 1)

consumer.assgin(topics)

try {
    do {
        val records = consumer.poll(Duration.ofMillis(1000))
        records.forEach {
            println("result : $it")
        }
    } while (!records.isEmpty)
} catch (e: Exception) {
    println(e.message)
} finally {
    consumer.close()
}

do it check session.timeout.ms, max.pool.interval.ms or hearbeat.interval.ms?是否检查 session.timeout.ms、max.pool.interval.ms 或 heartbeat.interval.ms? i think if kafka consumer don't use subscribe method, it don't check.我认为如果 kafka 消费者不使用订阅方法,它不会检查。

Both subscribe() and assign() will check for session.timeout.ms,max.pool.interval.ms and other properties that you specify during consumer creation. subscribe()assign()都将检查 session.timeout.ms、max.pool.interval.ms 和您在创建消费者期间指定的其他属性。

Difference between subscribe() and assign() is that when using subscribe()assign()的区别在于使用时

subscribe() uses group-id in the consumer properties and helps in dynamic partition assignment and consumer group coordination subscribe() 在消费者属性中使用group-id并有助于动态分区分配和消费者组协调

assign will manually assign a list of partitions to this consumer. assign 将手动分配一个分区列表给这个消费者。 and this method does not use the consumer's group management functionality (where no need of group.id )并且此方法不使用消费者的组管理功能(不需要group.id

More information here: https://stackoverflow.com/questions/53938125/kafkaconsumer-java-api-subscribe-vs-assign#:~:text=Subscribe%20makes%20use%20of%20the,to%20a%20list%20of%20topics .更多信息在这里: https://stackoverflow.com/questions/53938125/kafkaconsumer-java-api-subscribe-vs-assign#:~:text=Subscribe%20makes%20use%20of%20the,to%20a%20list%20of %20 个主题

Thanks.谢谢。 I tested like it.我测试喜欢它。

properties[ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG] = 10000
val consumer = KafkaConsumer<String, String>(properties)
val partitions = mutableListOf<TopicPartition>().apply {
    for (i in 0 until 1) {
        add(TopicPartition("TEST", i))
    }
}
consumer.assgin(partitions)
Threed.sleep(20000L)

try {
    do {
        val records = consumer.poll(Duration.ofMillis(1000))
        records.forEach {
            println("result : $it")
        }
    } while (!records.isEmpty)
} catch (e: Exception) {
    println(e.message)
}

but, it worked well.但是,它运作良好。 Did I do something wrong on the test?我在考试中做错了吗?

暂无
暂无

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

相关问题 在 Kafka 消费者配置中将 max.poll.interval.ms 设置为大于 request.timeout.ms 的负面影响是什么 - What is negative effects of setting max.poll.interval.ms larger than request.timeout.ms in Kafka consumer configs Spring 云 stream 卡夫卡消费者卡在长时间运行的作业和 max.poll.interval.ms 的大值 - Spring cloud stream Kafka consumer stuck with long running job and large value for max.poll.interval.ms 更改Kafka配置max.poll.interval.ms导致一名消费者卡在(重新)加入组中 - Change Kafka configuration max.poll.interval.ms causes one consumer stuck at (Re-)joining group Apache Kafka-了解在poll()方法中作为参数存在的超时与fetch.max.wait.ms之间的关系 - Apache Kafka- Understanding the relationship between timeout present as a parameter in the poll() method and fetch.max.wait.ms Spring Kafka,覆盖 max.poll.interval.ms? - Spring Kafka, overriding max.poll.interval.ms? 使用Kafka客户池是否正确? - Is it correct to use Kafka consumer pool? Consumer CommitFailedException - 后续调用 poll() 之间的时间长于配置的 max.poll.interval.ms - Consumer CommitFailedException - time between subsequent calls to poll() was longer than the configured max.poll.interval.ms 如何知道在 java kafka 应用程序客户端中是否达到了 max.poll.interval.ms? - How to know if max.poll.interval.ms is reached in java kafka application client? Kafka poll 和 max.poll.interval.ms - 批处理最佳实践 - Kafka poll and max.poll.interval.ms - Batch Processing best practices Kafka 生产者配置:为什么 request.timeout.ms 应该大于 replica.lag.time.max.ms - Kafka producer config: Why request.timeout.ms should be larger than replica.lag.time.max.ms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM