apache-kafka - 更改 Kafka 中的订阅主题
问题描述
我想在 Kafka 中测试更改订阅主题,所以我这样编码。
for (int count = 0; count < 30000; count++) {
consumer.subscribe(Collections.singletonList("test1"));
consumer.unsubscribe();
consumer.subscribe(Collections.singletonList("test2"));
ConsumerRecords<String, Integer> records = consumer.poll(100);
for (ConsumerRecord<String, Integer> record : records) {
String msgString = String.format("key:%s, value:%d, partition:%d offset:%d",
record.key(), record.value(), record.partition(), record.offset());
System.out.println(msgString);
}
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
但是数据要么不被轮询,要么只被部分轮询。我该如何解决?
解决方案
推荐阅读
- javascript - 为什么方向键导航在反转方向时会返回错误的值?
- python - 在运行的 Flask 应用程序中编辑内存中的字典
- html - 这些输入从哪里获得它们的“虚构”属性?
- python - Python + FastAPI + Gunicorn + Nginx + Oracle Cloud VM,网站未显示
- r - R 中的并行处理 - 使用 mclapply() 与 pbmclapply() 设置种子
- javascript - Web Audio API source.start() 仅在第二次调用时播放(在 safari 中)
- python - 使用 dict() 与 to_dict() 将 pandas Series 转换为字典:有什么细微差别?
- javascript - 修改 OnEdit 函数
- unit-testing - WrapperTestResponse' 对象没有属性 'text'
- variables - jenkins 环境注入器插件错误