Add payload conversion to SQS listener
chrylis opened this issue · 1 comments
When an SQS message arrives, the payload is always of type String
, but SQS usually does not carry a contentType
header. This means that the standard Jackson converter in Spring Integration is unable to handle the payload, and the flow .convert(PayloadType.class)
fails due to not having a matching converter.
It appears from the linked issue that the underlying SQS message listener has its own Jackson converter that operates in non-strict mode, permitting parsing of string values. It would be helpful to be able to say
var sqs = new SqsMessageDrivenChannelAdapter(sqsClient, "my-queue");
sqs.setPayloadType(PayloadType.class);
IntegrationFlows.from(sqs)
...
If that is not practical, then guidance on how to make conversion happen without requiring a contentType
in the original SNS message would be appreciated.
Spring Integration: 5.5.15
Spring Integration AWS: 2.5.2
The SqsMessageDrivenChannelAdapter
does not deal with those HandlerMethodArgumentResolver
s.
It has its own internal private class IntegrationQueueMessageHandler extends QueueMessageHandler {
with just plain override:
protected void handleMessageInternal(Message<?> message, String lookupDestination) {
...
sendMessage(messageToSend);
}
So, the conversion you mention is really out of this channel adapter scope.
The convert()
you mention is not going to work out-of-the-box because there is no simple org.springframework.core.convert.converter.Converter
implementation for JSON.
However the solution for you is like this:
.transform(Transformers.fromJson(PayloadType.class))
Closing as Works as Designed