spring - 使用 DeadLetterPublishingRecoverer 发布 Json 反序列化错误不会发布原始有效负载
问题描述
我正在使用 Spring Boot 2.3.1 并希望发布无法使用 DeadLetterPublishingRecoverer 反序列化的记录。
一切看起来都很好,除了原始有效负载没有写入 DLT 主题。相反,我看到它是 Base64 编码的。
在另一篇文章中,我读到这是由 Kafka 模板中使用的 JsonSerializer 引起的,因此我尝试使用不同的模板。但现在我得到一个序列化异常:
org.apache.kafka.common.errors.SerializationException: Can't convert value of class [B to class org.apache.kafka.common.serialization.BytesSerializer specified in value.serializer
使用 StringSerializer 时会发生类似的异常。
我的代码如下所示:
@Autowired
private KafkaProperties kafkaProperties;
private ProducerFactory<String, String> pf() {
return new DefaultKafkaProducerFactory<>(kafkaProperties.buildProducerProperties());
}
private KafkaTemplate<String, String> stringTemplate() {
return new KafkaTemplate<>(pf(), Collections.singletonMap(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class));
}
@Bean
public SeekToCurrentErrorHandler errorHandler() {
SeekToCurrentErrorHandler eh = new SeekToCurrentErrorHandler(new DeadLetterPublishingRecoverer(stringTemplate()));
eh.setLogLevel(Level.WARN);
return eh;
}
解决方案
5分钟后才发现。
我不得不ByteArraySerializer
改用。
推荐阅读
- scala - 变异隐式“上下文”参数
- angular - 如何在角度的ngx图表上设置工具提示
- vba - 已解决:无法弄清楚如何让“.EntireRow.Delete”删除另一个工作表中的单元格
- python-3.x - 使用 DenseVariational 层的 Tensorflow-Probability 网络中的参数数量
- python - 通过从文本文件中获取名称来复制文件。- Python
- flutter - Flutter:带有 NestedScrollView 和 SliverAppBar 的选项卡
- swiftui - 有没有办法通过 .onLongPressGesture 将第三个切换选项添加到开/关状态?
- php - 使用 cookie 登录且没有 php 会话时重新登录?
- python-3.x - 基于逗号将值 0 添加到现有列
- git - 避免将 png 图像添加到 git