目标是读取通过网络发出的数据。
在数据生成方面,我有一个向stdout喷出的应用程序。此数据的内容是JSON字符串。
我在做什么(在Linux Mint 17上,使用BSD风格的netcat):
数据生成:
my_app_which_outputs_json | netcat localhost 9999
在SpringXD中:(带xd-singlenode
)
xd:>stream create --name tcptest --definition "tcp --decoder=LF --port=9999 | file " --deploy
Created and deployed new stream 'tcptest'
输出:
/tmp/xd/output$ cat tcptest.out
82,117,110, ... (etc, lots more bytes)
我确定这是用户错误,但不确定要更改哪些内容以使其正确。
我应该注意,如果我这样做,它会按预期工作:
my_app_which_outputs_json > /tmp/somefile.txt
...
xd:>stream create --name filetest --definition "tail --name=/tmp/somefile.txt | file" --deploy
答案 0 :(得分:2)
根据您自己的回答,转换器当前未配置为了解byte[]
可以转换为内容类型为application/json
的字符串。
当然,即使我们将其配置为执行此操作,也无法确定内容是否真的是JSON。
答案 1 :(得分:1)
我将以下内容添加到我的流defn中,现在正在按照我的预期进行操作。我在" Type Conversion"中找到了这个。文档部分。
stream create --name tcptest \
--definition "tcp --decoder=LF --port=9999 --outputType=text/plain \
| file " --deploy
(新行和回溯不在我的实际代码中,但用于提高可读性。)
我也试过了... --outputType=application/json...
但没有用。不完全确定原因。
答案 2 :(得分:1)
text / plain激活ByteArrayToStringMessageConverter。 application / json目前没有。我创建了https://jira.spring.io/browse/XD-2512来解决此问题