Hello,
I've been trying to perform HTTP requests from a Flink Program but I wasn't successful :-(. Does anybody here has done this before and can point me to an working library? I've attached a small demo project in case someone wants to try to solve this. Best, -- Ulf Thomas Software Developer relayr flink-http-request.zip (14K) Download Attachment |
Hi Ulf, I’ve had similar problem, before but from a sink perspective: I had to create a HTTP sink for a Kafka REST API. I’ve used scalaj-http
https://github.com/scalaj/scalaj-http which is a wrapper for the corresponding Java lib.
For example,
https://github.com/scalaj/scalaj-http For example class
HttpSink extends SinkFunction[Message]{ I image for a http source, you could send a request to the REST API periodically and convert the micro-batches into a stream. I’d love to know about other alternatives.
Cheers, Alex From:
Ulf Thomas <[hidden email]> Hello, I've been trying to perform HTTP requests from a Flink Program but I wasn't successful :-(. Does anybody here has done this before and can point me to an working library? I've attached a small demo project in case someone wants to try to solve this. Best, -- -- |
Hi Ulf, I've done HTTP requests in Flink using OkHttp library. I found it practical and easy to use. Here is how I used it to make a POST request for each incoming element in the stream and ouput the response: DataStream<String> stream = .... stream.map(new RichMapFunction<String, String>() { OkHttpClient client; @Override public void open(Configuration config) throws IOException { client = new OkHttpClient(); } @Override public String map(String in) throws Exception { okhttp3.Request request = new okhttp3.Request.Builder() .url("http://localhost:8080") .post(RequestBody.create(MediaType.parse("text/plain; charset=utf-8"), in)) .build(); Response response = client.newCall(request).execute(); if (response.code() != 200) { throw new Exception("Failed request"); } String result = response.body().string(); return result; } }) I hope this helps. Best, Yassine 2017-03-02 14:17 GMT+01:00 Alex De Castro <[hidden email]>:
|
Free forum by Nabble | Edit this page |