Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple hello world example for Flink

Tags:

apache-flink

I am looking for the simplest possible example of an hello-world experience with Apache flink.

Assume I have just installed flink on a clean box, what is the bare minimum I would need to do to 'make it do something'. I realize this is quite vague, here are some examples.

Three python examples from the terminal:

python -c "print('hello world')"
python hello_world.py
python python -c "print(1+1)"

Of course a streaming application is a bit more complicated, but here is something similar that I did for spark streaming earlier:

https://spark.apache.org/docs/latest/streaming-programming-guide.html#a-quick-example

As you see these examples have some nice properties:

  1. They are minimal
  2. There are minimal dependencies on other tools/resources
  3. The logic can be trivially adjusted (e.g different number or different separator)

So my question:

What is the simplest hello world example for Flink


What I found so far are examples with 50 lines of code that you need to compile.

If this cannot be avoided due to point 3, then something that satisfies points 1 and 2 and uses (only) jars that are shipped by default, or easily available from a reputable source, would also be fine.

like image 699
Dennis Jaheruddin Avatar asked Jun 14 '26 16:06

Dennis Jaheruddin


1 Answers

Ok, how about this:

public static void main(String[] args) throws Exception {
  final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

  env.fromElements(1, 2, 3, 4, 5)
    .map(i -> 2 * i)
    .print();

  env.execute();
}
like image 95
David Anderson Avatar answered Jun 18 '26 01:06

David Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!