自定义AvroSchemaMessageConverter未注册

时间:2019-12-20 21:38:05

标签: spring-cloud-stream

我有一个@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中?

1 个答案:

答案 0 :(得分:0)

添加@StreamMessageConverter作为Oleg Zhurakousky建议为我解决了这个问题。