【发布时间】:2019-04-08 22:31:31
【问题描述】:
我有这个流程:
@Bean
public IntegrationFlow flow(){
return IntegrationFlows.from(QueueMessageSink.INPUT)
.transform(Transformers.fromJson(QueueMessage.class))
.<QueueMessage, DTOMessage> transform(queueMessage -> new DTOMessage(/* transform logic */))
.handle(Http.outboundGateway(uri).httpMethod(HttpMethod.POST))
.channel("nullChannel")
.get();
}
基本上,我正在从队列中读取消息并将其发布到 REST 端点。
队列中的消息以 Content-type application/octet-stream 到达,因此我已按以下方式配置队列:
spring.cloud.stream.bindings.my-queue.contentType=application/octet-stream
消息已正确地从 JSON 转换为 QueueMessage 以及从 QueueMessage 转换为 DTOMessage,但在尝试发布 DTOMessage 时出现以下异常:
Caused by: org.springframework.messaging.MessageHandlingException: HTTP request execution failed for URI; nested exception is org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [com.example.DTOMessage] and content type [application/octet-stream]
我认为(也许我错了)Http.outboundGateway 正在从 Spring 集成消息的标头中读取内容类型 application/octet-stream。
解决此问题的正确方法是什么?我想一个可能的解决方案是将内容类型更改为 application/json,但我不确定这是否是最简单的方法(我也不知道该怎么做)。
提前致谢。
【问题讨论】:
标签: spring spring-integration spring-cloud-stream