59987

Spring XD: “tcp” source outputs byte array instead of string? How to output regular text?

Question:

The goal is to read data emitted over the network.

On the data generation side I have an app which spews to stdout. The content of this data is a JSON string.

Here's what I'm doing (on Linux Mint 17, using an BSD flavored netcat):

<em>data generation:</em>

my_app_which_outputs_json | netcat localhost 9999

<em>In SpringXD:</em> (with xd-singlenode)

xd:>stream create --name tcptest --definition "tcp --decoder=LF --port=9999 | file " --deploy Created and deployed new stream 'tcptest'

<em>Output:</em>

/tmp/xd/output$ cat tcptest.out 82,117,110, ... (etc, lots more bytes)

I'm sure this is user error, but not sure what to change to make it right.

I should note that if I do this, it works as expected:

my_app_which_outputs_json > /tmp/somefile.txt ... xd:>stream create --name filetest --definition "tail --name=/tmp/somefile.txt | file" --deploy

Answer1:

Following up to your own answer, the converters are currently not configured to understand that a byte[] can be converted to a String with content type application/json.

Of course, even if we configured it to do so, it wouldn't be able to determine if the content really is JSON.

Answer2:

I added the following to my stream defn and it is now doing what I expected. I found this in the "Type Conversion" section of the documentation.

stream create --name tcptest \ --definition "tcp --decoder=LF --port=9999 --outputType=text/plain \ | file " --deploy

(The newlines and backwhacks are not in my actual code, but are used for readability.)

I also tried ... --outputType=application/json... which did not work. Not entirely sure why.

Answer3:

text/plain with a byte[] payload activates a ByteArrayToStringMessageConverter. application/json does not currently. I have created <a href="https://jira.spring.io/browse/XD-2512" rel="nofollow">https://jira.spring.io/browse/XD-2512</a> to address this

Recommend

  • PHP base64_decode C# equivalent
  • CSVParser processes LF as CRLF
  • Bash: How to do a variable expansion within an arithmetic expression?
  • How to create new layer or new protocol with scapy?
  • Special Characters in Google Calculator
  • PDO connection to MySQL database refused
  • Cannot log in using SQL authentication ONLY from a remote server
  • R. how to make matrix which have equal rows
  • How do I chomp a string if I have Perl 4?
  • How can I set the buffer size for the underneath Socket UDP?
  • Issue when joining serf nodes located in different Docker containers
  • Streaming data from a NVarchar(Max) column using c#
  • Checking whether the server is on/off
  • Determining the length of a read stream in node js
  • Converting raw frames into webm live stream
  • C# Networkstream reads nothing
  • How to capture enclosing scope in Runnable
  • Does the failbit effect the call ignore on cin?
  • Installing SSL on AWS EC2 Bitnami Mean Stack
  • Gstreamer1.0 : link a decodebin to videoconvert
  • XNU incudes in Kext
  • Unzip archive in .Net CORE 1.0
  • CORS with socket.io
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Prevent Tomcat from caching request during starup
  • Salesforce Different WSDL files and when to use
  • Access Android Market through SSH tunnel
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Play WS (2.2.1): post/put large request
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • Bad request using file_get_contents for PUT request in PHP
  • Build own AppleScript numerical error handling
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?