MessageConversionException: Cannot convert from Object to RabbitPropertiesCacheChannel for generic message

Published
Updated

Your Spring AMQP beans are likely not defined in the correct order or Spring cannot find an appropriate MessageConverter bean and your message is unable to be processed.

Defining a MessageConverter Bean

To make sure your MessageConverter bean is defined correctly, ensure the following conditions are met:

  • Your MessageConverter bean is marked correctly with a @Bean annotation and is contained in a class marked with a @Configuration annotation.
  • Your package scan and component scan configuration is processing the class in which your bean is defined. For more info on this, see my article on Spring Package Scanning.
  • You have a message converter bean defined. See below on how to define two kinds message converters (only use one):
    import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 
    import org.springframework.amqp.support.converter.Jackson2XmlMessageConverter; 
    

// For encoding JSON Messages @Bean Jackson2JsonMessageConverter jsonMessageConverter() { return new Jackson2JsonMessageConverter(); }

// For encoding XML Messages @Bean Jackson2XmlMessageConverter xmlMessageConverter() { return new Jackson2XmlMessageConverter(); }