Flow 102

NB: this post was updated 8th Jan 2018 to account for changed image names and invocation being “hot” by default.

If you haven’t read Flow 101 yet, I encourage you to start there and get grounded in what Flow is, what it’s for and how it works.

In this post I’ll go through how to build a more complex Flow with parallelism and asynchronous chaining. I’ll assume you have set up the services as described in the Flow 101.

The demo Flow

An app which:

reads some text

greps for a given keyword

counts the matching lines

prints the count

prints the file header

In your shell, it might look something like:

Installing helper functions

One of the cool things about Fn is that because it’s based on Docker, functions can be written in any language — even Bash!

Clone this repo of simple Bash functions and deploy them all:

You can test all of these individually, for example:

Creating our Flow function

In a new directory called word-flow:

And, make HelloFunction.java look like this:

It’s worth reading this code carefully, remembering that anything returning a FlowFuture object is an asynchronous call, which can be chained with thenApply, thenCompose and the other Flow API methods.

We’ll want some test data:

Deploy the function, and remember to configure the app with the location of the Flow Server (aka “completer”):