Spring Cloud - SQS

妖精的绣舞 提交于 2020-01-03 08:41:20

问题


I'm trying to get a simple queue handler working with the Spring Cloud framework. I've successfully got the message handler polling the queue, However. The problem I'm seeing is that when I post a message to the queue, my handler is failing to unmarshall the payload in to the required java Object.

@MessageMapping("MyMessageQueue")
@SuppressWarnings("UnusedDeclaration")
public void handleCreateListingMessage(@Headers Map<String, String> headers, MyMessage message) {
    //do something with the MyMessage object
}

The error I'm getting is

No converter found to convert to class MyMessage

As I understand it, the @MessageMapping should use Jackson to unmarshall my JSON payload into a MyMessage object. However its complaining that it cannot find a converter.

Has anyone come across this?

I'm using the 1.0.0.BUILD-SNAPSHOT version of Spring Cloud.


回答1:


Jackson is only used if a contentType header is set with value application/json on the SQS message. Otherwise the converters do not know what type of content is contained in the message's payload and the right converter cannot be chosen.

If you use QueueMessagingTemplate#convertAndSend as in the reference application, the contentType header will automatically be set.



来源:https://stackoverflow.com/questions/27723439/spring-cloud-sqs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!