I'm using an asyncronous message receiver in Spring-AMQP to receive messages. Currently only messages with JSON content are handled, but I have a requirement to also handle messages with XML content. My current implementation of MessageListener
has a MessageConverter
injected and uses it in onMessage(Message)
, like this:
MyMessage myMessage = (MyMessage) jsonConverter.fromMessage(message);
In order to support different content types I could obviously use the MessageProperties
to interrogate the content-type header and manually select a converter to use. But that seems like a lot of work, like Spring should provide some better support for this scenario. I was hoping to find a generic MessageConverter
implementation that would map from content-types to specific converters, but there doesn't seem to be such a thing.
Is my best option to write a delegating converter like that? Or is there a way to configure the ListenerContainer
to support both async receiving and multiple converters that are automatically used as needed?