How do I convert from a Json Byte Array for AMQP in Spring Boot?

痴心易碎 提交于 2019-12-02 11:31:04

According your stack trace there is nothing in the Listener Container to do with your incoming JSON. So, it happens as just pass through with byte[] as a pyalod. What you end up is just an attempt to convert that byte[] to the expected type on your @RabbitListener method. For that purpose, when you don't have a JSON information to convert on the listener container level, you need to configure a DefaultMessageHandlerMethodFactory with desired MappingJackson2MessageConverter. It can be achieve with the RabbitListenerConfigurer:

    @Bean
    public DefaultMessageHandlerMethodFactory myHandlerMethodFactory() {
        DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
        factory.setMessageConverter(new MappingJackson2MessageConverter());
        return factory;
    }


    @Override
    public void configureRabbitListeners(RabbitListenerEndpointRegistrar registrar) {
        registrar.setMessageHandlerMethodFactory(myHandlerMethodFactory());
    }

That MappingJackson2MessageConverter can be configured as a bean for your custom ObjectMapper injection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!