Packaging For Deployment

Stateful Functions applications can be packaged as either standalone applications or Flink jobs that can be submitted to a cluster.

Images

The recommended deployment mode for Stateful Functions applications is to build a Docker image. This way, user code does not need to package any Apache Flink components. The provided base image allows teams to package their applications with all the necessary runtime dependencies quickly.

Below is an example Dockerfile for building a Stateful Functions image with both an embedded module and a remote module for an application called statefun-example.

  1. FROM flink-statefun:2.1.0
  2. RUN mkdir -p /opt/statefun/modules/statefun-example
  3. RUN mkdir -p /opt/statefun/modules/remote
  4. COPY target/statefun-example*jar /opt/statefun/modules/statefun-example/
  5. COPY module.yaml /opt/statefun/modules/remote/module.yaml

The Flink community is currently waiting for the official Docker images to be published to Docker Hub. In the meantime, Ververica has volunteered to make Stateful Function’s images available via their public registry: FROM ververica/flink-statefun:2.1.0 You can follow the status of Docker Hub contribution here.

Flink Jar

If you prefer to package your job to submit to an existing Flink cluster, simply include statefun-flink-distribution as a dependency to your application.

  1. <dependency>
  2. <groupId>org.apache.flink</groupId>
  3. <artifactId>statefun-flink-distribution</artifactId>
  4. <version>2.1.0</version>
  5. </dependency>

It includes all of Stateful Functions’ runtime dependencies and configures the application’s main entry-point.

Attention: The distribution must be bundled in your application fat JAR so that it is on Flink’s user code class loader

  1. ./bin/flink run -c org.apache.flink.statefun.flink.core.StatefulFunctionsJob ./statefun-example.jar

The following configurations are strictly required for running StateFun application.

  1. classloader.parent-first-patterns.additional: org.apache.flink.statefun;org.apache.kafka;com.google.protobuf