Support Questions

Find answers, ask questions, and share your expertise

How to : HTTP Stream in flink

avatar
Rising Star

Which methods/objects does Flink provide in order to enable users to read HTTP streams?

1 ACCEPTED SOLUTION

avatar
Rising Star

@Robert Metzger,

I have prepared the Custom HTTPJSONStream reader and here is the attached code.

loganalytics.txt-> This is the main Class which fetches the data from the custom source. In our case its JSON via HTTP url.

httpjsonstream.txt -> This class implements the SourceFunction and provides a SourceContext of custom-type FlinkJSONObject

flinkjsonobject.txt -> This class uses java.net.* and javax.json.* to connect to provided URL and get the content in JSON Object format.

The logic can be applied on the JSONObject to get the desired results.

Please suggest if any changes can be made.

View solution in original post

7 REPLIES 7

avatar
Master Mentor
@Hemant Kumar

The best information on this topic can be found on flink site. https://flink.apache.org/news/2015/02/09/streaming...

https://github.com/dataartisans/flink-streaming-de...

Not sure if it helps to customize for HTTP

avatar
Rising Star

Thanks @Neeraj Sabharwal

For HTTP, I am in a state where I have to write a custom SourceFunction. Before I try it, I am exploring if there is a possibility to Handle HTTP Requests by using any of the existing StreamExecutionEnvironment functions/objects.

I am also trying to handle HTTP Stream for Flink using NiFi Connector as mentioned here

I hope either of these will help me in achieving desired results. 🙂

avatar

avatar
Explorer

Sorry for the late reply. As I said in the other thread, I would recommend using a SourceFunction here. Feel free to post your code here as well, I can review it and give some hints for improving it.

avatar
Rising Star

@Robert Metzger,

I have prepared the Custom HTTPJSONStream reader and here is the attached code.

loganalytics.txt-> This is the main Class which fetches the data from the custom source. In our case its JSON via HTTP url.

httpjsonstream.txt -> This class implements the SourceFunction and provides a SourceContext of custom-type FlinkJSONObject

flinkjsonobject.txt -> This class uses java.net.* and javax.json.* to connect to provided URL and get the content in JSON Object format.

The logic can be applied on the JSONObject to get the desired results.

Please suggest if any changes can be made.

avatar
Explorer

Thank you for posting the code here @Hemant Kumar. Sorry for the delay, I've now looked at and it looks good. If you want to optimize the code, I would try to move the code from the FlinkJSONObject constructor into the HTTPJSONStream class. It seems that the do/while loop is actually controlled from within the FlinkJSONObject.

avatar
Rising Star

Thanks a lot @Robert Metzger