未注册自定义AvroSchemaMessageConverter

问题描述 投票:0回答:1

我有一个@SpringBootApplication类,其中定义了以下bean:

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public MessageConverter avroSchemaMessageConverter() {
  return new AvroSchemaMessageConverter(MimeType.valueOf("avro/bytes"));
}

[当我运行@SpringBootTest并对其进行调试时,我注意到在我为CompositeMessageConverterFactory的构造函数断点之前没有创建此bean。当自定义转换器的列表作为参数传递给此类时,我的自定义AvroSchemaMessageConverter从未被注册。

当我稍后在测试中尝试将Avro消息发送到我的@Output通道时,此情况导致以下错误:

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的Application Context中?

spring-cloud-stream
1个回答
0
投票

作为Oleg Zhurakousky建议为我添加此流,添加@StreamMessageConverter。

© www.soinside.com 2019 - 2024. All rights reserved.