我使用的是Spring Cloud Edgware。SR3和Spring Cloud Stream 2.0.1发布。
我使用spring cloud stream 2.0创建了测试处理器应用程序。创建了样本流:
stream create TEST1 --definition "http --server.port=8888 | testprocessor | uploader --spring.cloud.stream.bindings.input.contentType='text/plain1' "部署在Spring云本地服务器上。
//testprocessor apps method signature is
@StreamListener(Processor.INPUT)
@sendto(Processor.OUTPUT)
public String transform(Object payload) {
}在此应用程序的application.properties中,我已配置了以下属性spring.cloud.stream.bindings.input.content-type=application/json;
输入数据示例:
http post --contentType 'application/json' --data '{\"isbn\": \"1599869772", "title": "The Art of War", "author": "Sun Tzu"}' --target http://localhost:8888当我发布上面的示例数据时,我总是得到对象有效负载是像[B@5b2ff6e7这样的byte[]对象,而不是得到实际的JSON字符串。你能在这个问题上提供帮助吗?
注意:如果我使用spring cloud stream 1.3.1版本构建相同的测试处理器应用程序。它工作得很好。我正在获取JSON字符串。为什么使用spring cloud stream 2.0.1不能工作
发布于 2018-10-31 22:05:03
transformer应用程序有一个expression选项,因此您可以这样做:
--expression='new String(payload)'您将在public String transform(Object payload)方法中获得一个JSON字符串。
相关的GH问题:https://github.com/spring-cloud-stream-app-starters/transform/issues/6
https://stackoverflow.com/questions/53083818
复制相似问题