如何在Spring-AMQP中使用Jackson2JsonMessageConverter处理内容类型为null [英] How do I handle content-type null with Jackson2JsonMessageConverter in Spring-AMQP

查看:2739
本文介绍了如何在Spring-AMQP中使用Jackson2JsonMessageConverter处理内容类型为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不是一个问题,则

If it's not one problem, it's another... I seem to have gotten the 2 previous problems fixed but now when running outside of a test context, with a stood up application I see this.

o.s.a.s.c.Jackson2JsonMessageConverter   : Could not convert incoming message with content-type [null], 'json' keyword missing.

像以前一样,此消息看起来很清晰.哎呀,事情甚至可以在独立的测试环境中运行,但是,当在独立的服务器上运行时,代码似乎采用了不同的路径,并且由于相同的原因而失败,但是通过了不同的组件.

Like before, this message seems fairly clear. Heck, things even worked in a standalone test context, however when running in a standalone server the code seems to be taking a different path and is failing for the same reason but via a different component.

@Configuration
open class MessagingConfig {

    @Bean
    open fun jackson2Json(om: ObjectMapper): SmartMessageConverter {
        return Jackson2JsonMessageConverter(om)
    }

    @Bean
    open fun mappingJackson2(om: ObjectMapper): MappingJackson2MessageConverter {
        val mc = MappingJackson2MessageConverter()
        mc.objectMapper = om
        return mc
    }

    @Bean
    open fun defaultMessageHandlerMethodFactory(jackson: MappingJackson2MessageConverter): DefaultMessageHandlerMethodFactory {
        val factory = DefaultMessageHandlerMethodFactory()
        factory.setMessageConverter(jackson)
        return factory
    }


    @Bean
    open fun builder(): Jackson2ObjectMapperBuilderCustomizer {
        return Jackson2ObjectMapperBuilderCustomizer {
            it.modules(JavaTimeModule(), KotlinModule())
            it.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
        }
    }


    @Configuration
    open class RabbitConfigurer(val dmhmf: DefaultMessageHandlerMethodFactory) : RabbitListenerConfigurer {
        override fun configureRabbitListeners(registrar: RabbitListenerEndpointRegistrar?) {
            registrar?.messageHandlerMethodFactory = dmhmf
        }
    }
}

推荐答案

您可以将MessagePostprocessor添加到容器工厂,以使用content_id属性增强消息.

You can add a MessagePostprocessor to the container factory to enhance the message with a content_id property.

factory.setAfterReceivePostProcessors(m -> {
    m.getMessageProperties().setContentId("application/json");
    return m;
}

这篇关于如何在Spring-AMQP中使用Jackson2JsonMessageConverter处理内容类型为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆