Flink Project Template

The Quickstart Archetype serves as a template for an Apache Flink streaming application. You can use the Archetype to add source, sink and computation to the template. Like this you can practice the development of a simple Flink application, or use the Archetype as the starting point for a more complex application including state,watermark and checkpoint.

The Flink quickstart archetype can be used to quickly build a basic Flink streaming project.
  1. Perform the following commands to create the archetype locally:
    git clone https://github.com/cloudera/flink-tutorials
    cd flink-tutorials
    cd flink-quickstart-archetype
    git checkout CSA-
    mvn clean install
    cd ..

    The following entry should be seen in your local catalog:

    cat ~/.m2/repository/archetype-catalog.xml
  2. Generate the project skeleton with the following commands:
    mvn archetype:generate \
          -DarchetypeGroupId=com.cloudera.flink \
          -DarchetypeArtifactId=flink-quickstart-archetype \
  3. Provide basic information about the streaming application.
    You can choose to customize configurations yourself or use automatically generated information.
    • To use automatically generated information, press Enter.
    • If you choose to customize configuration, set the following properties:
      Define value for property 'groupId': com.cloudera.flink
                                      Define value for property 'artifactId': sample-project
                                      Define value for property 'version' 1.0-SNAPSHOT: :
                                      Define value for property 'package' com.cloudera.flink: :
                                      Confirm properties configuration:
                                      groupId: com.cloudera.flink
                                      artifactId: sample-project
                                      version: 1.0-SNAPSHOT
                                      package: com.cloudera.flink
                                      Y: :
    The generated project will look like this:
    ├── pom.xml
    └── src
        └── main
            ├── java
            │   └── com
            │       └── cloudera
            │           └── flink
            │               └── StreamingJob.java
            └── resources
                └── log4j.properties 
  4. Open StreamingJob.java file.
    The archetype application will look like this:
    public class StreamingJob {
    	public static void main(String[] args) throws Exception {
    		final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    		DataStream<Integer> ds = env.fromElements(1,2,3,4);
    		env.execute("Flink Streaming Java API Skeleton");
  5. Customize the archetype application by adding source, stream transformation and sink to the Datastream class.
  6. Run the application with env.execute command.
You have built your Flink streaming project.
You can further develop your application, or you can run the Flink application archetype.