春季云 - SQS [英] Spring Cloud - SQS
问题描述
我试图让一个简单的队列处理程序与Spring框架的云计算工作。我已经成功地得到了消息处理程序轮询队列,但是。我看到的问题是,当我发布一条消息到队列中,我的处理程序失败来解读的有效载荷,将所需的Java对象。
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
据我了解,在@MessageMapping应该用杰克逊来解读我的JSON的有效载荷送入一个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.
有没有人遇到过这个?
我使用Spring云的1.0.0.BUILD-快照版本。
I'm using the 1.0.0.BUILD-SNAPSHOT version of Spring Cloud.
推荐答案
杰克逊只有当的contentType
头设置值,使用应用程序/ JSON
的SQS消息。否则,转换器不知道是什么类型的内容被包含在消息的有效载荷和右转换器不能选择
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.
如果您使用 QueueMessagingTemplate#convertAndSend
作为<一href="https://github.com/spring-cloud-samples/aws-refapp/blob/master/src/main/java/org/springframework/cloud/aws/sample/sqs/SqsController.java#L60">reference应用,在的contentType
头将被自动设置。
If you use QueueMessagingTemplate#convertAndSend
as in the reference application, the contentType
header will automatically be set.
这篇关于春季云 - SQS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!