Two listeners like that won't work - it will simply create two competing consumers on the same queue. One solution would be to use different queues (and different listeners).
If you want to use the same queue for both request types, probably the simplest solution would be to have your listener POJO return Object
(POJO or byte[]
) (Q2b) and use a custom MessageConverter
.
The custom messageConverter would be pretty simple; assuming you always get JSON on the inbound, it would always delegate to a JsonMessageConverter
in fromMessage()
and on the outbound side (toMessage
) should delegate to either a JsonMessageConverter
or a SimpleMessageConverter
:
if (object instanceof byte[]) {
return this.simpleMessageConverter.toMessage(object, messageProperties);
else {
return this.jsonMessageConverter.toMessage(object, messageProperties);
}
The SimpleMessageConverter
will set the contentType
property to application/octet-stream
but you can change that if you want after calling its toMessage
method (message.getMessageProperties().setContentType(...);
.