Simple Stream Producer
Step 1: Download the file Stream.java attached below.
Step 2: Open terminal and go to the folder in which you downloaded the file and compile the file using the command below. The command will produce will a Stream.class file in the same directory. The class file will be executed using java command next.
$ javac Stream.java
Step 3: Use the following command to stream a file with a specified rate (lines/second)
Usage: stream <file name> <port number> <lines per seconds>
Example:
$ java Stream /etc/passwd 9999 1
Above line streams /etc/passwd file on port 9999 at rate 1 line per sec.
Start streaming the file tweeter.json - 1 message per sec
$ java Stream ~/Downloads/datasets/tweets.json 9999 1
If you get the following error message
$ java Stream ~/Downloads/datasets/tweets.json 9999 1
java.net.SocketException: Address already in use
at java.net.PlainSocketImpl.socketListen(Native Method)
at java.net.AbstractPlainSocketImpl.listen(AbstractPlainSocketImpl.java:388)
at java.net.ServerSocket.bind(ServerSocket.java:377)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at java.net.ServerSocket.<init>(ServerSocket.java:128)
at Stream.<init>(Stream.java:11)
at Stream.main(Stream.java:72)
Find process that is using port 9999
$ sudo netstat -tulpn | grep 9999
If a process already occupies the port 9999, terminal will show the process details. Using the process id, kill the process. Process Id will be different.
$ sudo netstat -tulpn | grep 9999
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 18616/nc
[cloudera@quickstart python]$ sudo kill -9 18616