spring-cloud-stream - 自定义 AvroSchemaMessageConverter 未注册
问题描述
我有一个@SpringBootApplication
定义了以下bean的类:
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public MessageConverter avroSchemaMessageConverter() {
return new AvroSchemaMessageConverter(MimeType.valueOf("avro/bytes"));
}
当我运行 a@SpringBootTest
并对其进行调试时,我注意到在我对CompositeMessageConverterFactory
. 由于自定义转换器列表作为参数传递给此类,因此我的自定义 AvroSchemaMessageConverter 从未注册。
@Output
当我稍后在测试中尝试将 Avro 消息发送到我的频道时,这种情况会导致以下错误:
Caused by: java.lang.IllegalStateException: Failed to convert message: 'GenericMessage [payload={omitted for privacy reasons}, headers={id=omitted, contentType=avro/bytes, __TypeId__=com.example.ExampleRecord, timestamp=1576877638777}]' to outbound message.
at org.springframework.cloud.stream.binding.MessageConverterConfigurer$OutboundContentTypeConvertingInterceptor.doPreSend(MessageConverterConfigurer.java:389)
at org.springframework.cloud.stream.binding.MessageConverterConfigurer$AbstractContentTypeInterceptor.preSend(MessageConverterConfigurer.java:423)
at org.springframework.integration.channel.AbstractMessageChannel$ChannelInterceptorList.preSend(AbstractMessageChannel.java:608)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:443)
... 75 common frames omitted
如何确保在CompositeMessageConverterFactory
使用其转换器列表初始化之前将我的 bean 添加到 Spring 的应用程序上下文中?
解决方案
添加@StreamMessageConverter 作为Oleg Zhurakousky 建议为我解决了这个问题。
推荐阅读
- android - 更新应用程序版本时必须更改sqlite版本吗?
- javascript - 在 HTML 页面上按下按键时触发 i:active
- docker - 如何查看不同端口上运行的docker容器的日志
- python - 叠加灰度颜色通道
- javascript - 如何在jquery中动态传递值
- java - 希望在 Java Swing GUI 中验证 textField 和 comboBox
- tensorflow - 如何显示具有最高错误 keras 的所有示例
- javascript - 按钮 onclick 无法正常工作
- javascript - 无法使用循环更改 element.style.height 值
- c++ - 如何打印整个形状而不将其分成两个嵌套循环?