Reputation: 189
I have inheritted an application where two services(serviceA & serviceB) communicate using SQS. They use a payload-wrapper class as the message payload. However, instead of using a common definition they have defined the message payloads in each service (com.example.serviceA.PayloadWrapper & com.example.serviceA.PayloadWrapper).
When sending message using SQSTemplate (spring-cloud-aws-starter-sqs), the JavaType is getting added to the message and the other service is not able parse the payload.
as per the documentation(https://docs.awspring.io/spring-cloud-aws/docs/3.1.0/reference/html/index.html#specifying-a-payload-class-for-receive-operations) I have tried to configure the SQS template as follows,
SqsTemplate.builder()
.configureDefaultConverter(c -> {
c.setPayloadMessageConverter(messageConverter); //MappingJackson2MessageConverter
c.setPayloadTypeHeaderValueFunction(m -> null);
c.setPayloadTypeHeader("com.example.serviceA.PayloadWrapper");
}).sqsAsyncClient(sqsAsyncClient).build();
but with the above configuration I am receiving the following exception,
java.lang.IllegalArgumentException: payload must be instance of String: [B
can someone please help me with the correct configuration.
Upvotes: 0
Views: 105
Reputation: 189
Found the issue(s),
I had incorrectly configured the payload message converted (MappingJackson2MessageConverter) which lead to the above exception.
The outcome I was trying to achieve had nothing do with the message converter so I removed the configuration and kept it untouched. The final configuration looked like below,
SqsTemplate.builder()
.configureDefaultConverter(c -> {
c.setPayloadTypeHeaderValueFunction(m -> "com.example.serviceA.PayloadWrapper");
c.setPayloadTypeHeader("JavaType");
}).sqsAsyncClient(sqsAsyncClient).build();
Upvotes: 0