I'm using Spring 4.2 and spring-amqp 1.5.5 and I've implemented my own org.springframework.amqp.support.converter.MessageConverter
. This message converter is supposed to map between a org.springframework.amqp.core.Message
and a Java object by looking at a property contained in the message body. But I cannot find a way to apply this message converter to be used in combination with the @RabbitListener
annotation. What I want to do is something like this:
@RabbitListener
public void process(MyEvent myEvent) {
..
}
But Spring seems to be using a DefaultMessageHandlerMethodFactory
to which you can only assign instances of org.springframework.messaging.converter.MessageConverter
which is not the same type of MessageConverter that I'm using.
The reason for implementing my own org.springframework.amqp.support.converter.MessageConverter
is because we generate messages from non Java applications which doesn't add the magic __TypeId__
header used by Spring to determine the class to deserialize the body into.
I have tried to define a SimpleRabbitListenerContainerFactory
:
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(rabbitConnectionFactory());
factory.setMessageConverter(messageConverter());
return factory;
}
but it doesn't seem to be used (or at least it doesn't make any difference).
So my question is, how do I apply my org.springframework.amqp.support.converter.MessageConverter
?