Kafka java 消费者在轮询调用中仅获取几条消息,有时 none,有人可以帮助增加轮询计数
Kafka java consumer fetching only a few messages in a call to poll and sometimes none,Can someone help increase the poll count
我的配置:
props.put("sasl.mechanism", "PLAIN");
props.put("enable.auto.commit", "false");
props.put("auto.commit.interval.ms", "1000");
props.put("auto.offset.reset", "latest");
props.put("request.timeout.ms", 16000);
props.put("max.partition.fetch.bytes", "4194304");
props.put("max.poll.records","3000");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
ConsumerRecords 消费者记录 = consumer.poll(100);
您可以增加默认为 1 的使用者配置 fetch.min.bytes
以确保一次获取更多数据。但是,如果在 16secs
之后没有新数据到达主题(如您的 request.timeout.ms
配置中所设置),您仍然会看到获取零条消息的轮询。
这里是 consumer configs 上的 Kafka 文档中对配置 fetch.min.bytes
的完整描述:
fetch.min.bytes: The minimum amount of data the server should return for a fetch request. If insufficient data is available the request will wait for that much data to accumulate before answering the request. The default setting of 1 byte means that fetch requests are answered as soon as a single byte of data is available or the fetch request times out waiting for data to arrive. Setting this to something greater than 1 will cause the server to wait for larger amounts of data to accumulate which can improve server throughput a bit at the cost of some additional latency.
我的配置:
props.put("sasl.mechanism", "PLAIN");
props.put("enable.auto.commit", "false");
props.put("auto.commit.interval.ms", "1000");
props.put("auto.offset.reset", "latest");
props.put("request.timeout.ms", 16000);
props.put("max.partition.fetch.bytes", "4194304");
props.put("max.poll.records","3000");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
ConsumerRecords 消费者记录 = consumer.poll(100);
您可以增加默认为 1 的使用者配置 fetch.min.bytes
以确保一次获取更多数据。但是,如果在 16secs
之后没有新数据到达主题(如您的 request.timeout.ms
配置中所设置),您仍然会看到获取零条消息的轮询。
这里是 consumer configs 上的 Kafka 文档中对配置 fetch.min.bytes
的完整描述:
fetch.min.bytes: The minimum amount of data the server should return for a fetch request. If insufficient data is available the request will wait for that much data to accumulate before answering the request. The default setting of 1 byte means that fetch requests are answered as soon as a single byte of data is available or the fetch request times out waiting for data to arrive. Setting this to something greater than 1 will cause the server to wait for larger amounts of data to accumulate which can improve server throughput a bit at the cost of some additional latency.