spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
590 stars 373 forks source link

Add Automatic conversion Support (POJO to/from String) for FIFO SQS Queues #372

Open tmnuwan12 opened 6 years ago

tmnuwan12 commented 6 years ago

Bug Report

I am referring to the below feature: https://github.com/spring-cloud/spring-cloud-aws/issues/271 I am using spring-cloud-starter-aws (1.2.2.RELEASE).

In the project I wanted to use AWS FIFO queues and used the QueueMessagingTemplate's send(String ,Message).

The problem is you can put any type in the payload of the message and add FIFO headers. Things are working ok. But the serialization of the Message is done by calling String.valueOf(payload).. In this case if the payload is a POJO it's a toString(). This will cause issues when listening to the message as we can't re-create the POJO from toString() representation. Because (CompositMessageConverter in this case) message converters do not know how to create a POJO from the toString() representation.

To temporarily fix this issue I always convert the payload of the FIFO to a JSON string and sending it. Also I am setting the "application/json;charset=UTF-8" header in the Message. This way queue listeners can parse this using Jackson parser and re-create the POJO from the JSON.

Is there any fix for this? Instead of calling String.valueOf(message.payload()) - in the QueueMessageChannel class, there should be default way of handling. This should be similar to how normal queue sending/receiving works - the POJO to/from String happens automatically. When Message it's not.

tmnuwan12 commented 5 years ago

I look at how existing code works. I need some help where to look for when listening to the queue and how CompositeMessageConverter is applied on listeners. Went through the QueueMessagingTemplate listener class "receive" method but not sure it's the correct method to look for. If someone can point it out I can dig more deeper to make the enhancement happen.