spring-boot - springboot中使用@KafkaListener时,如何设置idleBetweenPolls
问题描述
"idleBetweenPolls" 是 spring-kafka 中一个方便的配置,用于调整消耗率。
但是,在检查 springboot 的源代码和文档时,似乎没有提到这个 props 或如何将某些特定值传播到 org.springframework.kafka.listener.ContainerProperties。
任何人都知道无论如何要实现上述目标?
解决方案
添加一个容器工厂定制器 bean:
@Component
class Customizer {
public Customizer(ConcurrentKafkaListenerContainerFactory<?, ?> factory) {
factory.getContainerProperties().setIdleBetweenPolls(5_000L);
}
}
这将在所有容器上设置它。
如果您只想在特定容器上设置它:
@Component
class Customizer2 {
public Customizer2(ConcurrentKafkaListenerContainerFactory<?, ?> factory) {
factory.setContainerCustomizer(container -> {
if (container.getContainerProperties().getGroupId().equals("theOneIWant") {
container.getContainerProperties().setIdleBetweenPolls(5_000L);
}
});
}
}
或者,配置您自己的工厂,而不是使用 Boot 的自动配置工厂。
推荐阅读
- ios - 如何更改水平滚动集合视图中单元格之间的水平间距
- node.js - 用于授权外部应用 NodeJS 的令牌
- c# - Control.InvokeRequired 在任务中为假
- git - Microsoft Sql Server 分析服务 (SSAS) 上的版本控制
- angular - 在现有的 Angular 9 应用程序中集成 express api
- kotlin - 枚举接口数组的类型推导失败
- wso2 - 授权策略 (PDP) 不适用于 WSO2 身份服务器 5.10.0 中的联合用户
- javascript - 如何等待元素完全加载到 DOM 中?
- sql - sql查询查找员工处理的订单
- c - D 类型限定符对强制类型转换没有意义