java - 整数类型的值在 DeadLetterPublishingRecoverer 上出现错误
问题描述
我试过这段代码,在这里:
@Bean
public ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory(
ConcurrentKafkaListenerContainerFactoryConfigurer configure,
ConsumerFactory<Object, Object> kafkaConsumerFactory,
KafkaTemplate<Object, Object> template) {
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
configure.configure(factory, kafkaConsumerFactory);
factory.setErrorHandler(new SeekToCurrentErrorHandler(new DeadLetterPublishingRecoverer(template),3));
return factory;
}
这部分的 int
factory.setErrorHandler(new SeekToCurrentErrorHandler(new DeadLetterPublishingRecoverer(template),3));
不允许使用数字 3,因为它需要 BackOff 而不是 int 类型。
解决方案
该构造函数在 2.3.x 中已弃用,并在 2.5.x 中删除。
请参阅文档:https ://docs.spring.io/spring-kafka/docs/current/reference/html/#seek-to-current
以前,配置是“maxFailures”(包括第一次交付尝试)。使用 FixedBackOff 时,它的 maxAttempts 属性表示传递重试次数(比旧的 maxFailures 属性少一)。此外,
maxFailures=-1
这意味着使用旧配置无限期重试,BackOff
您可以将 maxAttempts 设置为 Long.MAX_VALUE 对于 aFixedBackOff
并将 maxElapsedTime 保留为 a 中的默认值ExponentialBackOff
。
现在的等价物是
factory.setErrorHandler(new SeekToCurrentErrorHandler(new DeadLetterPublishingRecoverer(template), new FixedBackOff(0L, 2));
(不延迟 3 次交付尝试)。
推荐阅读
- python - 使用python删除字符串中的子字符串?
- angular - 离子原生 http post 调用不支持 responseType 作为 blob 用于从 WebService 下载 pdf
- python - 从只有列名的 pandas 空数据框创建字典
- webpack - 如何使用 webpack 延迟加载(动态导入)TinyMCE?
- discord.js - 使用 Djs12 隐藏频道
- keras - 将几个二进制列转换为多标签数组
- css - 模式正文文本超过 Bootstrap 4 中模式的宽度
- java - WSO2AM启动成功后出现奇怪错误
- flutter - 送餐应用程序:bloc 或 Provider 使用哪一个?
- ios - 如何在 React Native 中使用“原生”的 UI 观感?