Run Flink tasks on IDEA

IDEA is a commonly used IDE. If the flink task code we write can be run directly on IDEA, it will bring great convenience to learning and development. For example, after the code is changed, it will run immediately without deployment, breakpoints, and single-step debugging

Environmental information

  1. Computer: 2019 version 13-inch MacBook Pro, 2.3 GHz quad-core Intel Core i5, 8 GB 2133 MHz LPDDR3
  2. Operating system: macOS Catalina 10.15.3
  3. JDK:1.8.0_211
  4. Maven:3.6.0
  5. IDEA:2018.3.5 (Ultimate Edition)
  6. Flink version: 1.9.2

About genuine IDEA

For how to use genuine IDEA for free, please refer to "Free Application and Use of IntelliJ IDEA Commercial License Guide"

Development

  1. First make sure that maven is installed on your computer;
  2. Create a maven project for the flink task, find a clean directory and execute the following commands:
mvn \
archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-quickstart-java \
-DarchetypeVersion=1.9.2
  1. Follow the prompts to enter groupId, artifactId, version, package, etc .:
    Insert picture description here
  2. Now that the maven project has been generated, use IDEA to import this project, as shown below:
    Insert picture description here
  3. Import as maven:
    Insert picture description here
  4. What it looks like after successful import:
    Insert picture description here
  5. Modify StreamingJob.java to add the function of monitoring the local port 18081 , get the character string to do word count operation, and download the complete code here: https://raw.githubusercontent.com/zq2599/blog_demos/master/files/StreamingJob.java
    Insert picture description here
  6. The current code can be run, but the flink webpage is not yet accessible, the following error message will be displayed, and you need to continue to make some settings:
    Insert picture description here
  7. Download the flink-1.9.2 installation package, there is a jar used by the flink web service, the address is: https://www-eu.apache.org/dist/flink/flink-1.9.2/flink-1.9. 2-bin-scala_2.11.tgz
  8. flink-1.9.2-bin-scala_2.11.tgz download and unzip, there is a flink-dist_2.11-1.9.2.jar file in the lib directory , remember the location of this file, you will use it later;
  9. Go back to IDEA, right-click on the project, and click the menu Open Module Settings :
    Insert picture description here
  10. Do the following in the pop-up window, the purpose is to add jar to the project:
    Insert picture description here
  11. A window for selecting a file pops up, please select the file flink-dist_2.11-1.9.2.jar that you just prepared :
    Insert picture description here
  12. The setup work has been completed. Since the job of StreamingJob is to read the data on port 18081 of the machine, we need to start the service on port 18081, otherwise the StreamingJob will not be connected to the port when it is running. Open a console and execute the command: nc -l 18081
  13. Now you can run the StreamingJob, as shown in the figure below, right-click on the StreamingJob, select Run 'StreamingJob.main ()': you can start the flink task, if you want to interrupt the debugging, please select Debug 'StreamingJob.main ()'
    Insert picture description here
  14. Go back to the console where you just executed the nc command, enter some strings, such as "aaa bbb aaa", and then press Enter;
  15. Going back to IDEA, we can see that StreamingJob has read the data from port 18081 and output the statistical results:
    Insert picture description here
  16. Search for the keyword localhost in the IDEA console , as shown in the red box below, you can find the port of the flink webpage, I am here 62641 :
    Insert picture description here
  17. The browser visits http: // localhost: 62641 , as shown in the figure below, it can be seen that the flink webpage has been displayed normally, and the running tasks can also be seen:
    Insert picture description here
    At this point, the simplest IDEA's actual combat to run the flink task is completed, if you are also learning flink, hope this article can give you some reference;

Welcome to pay attention to my public number: programmer Xinchen

Insert picture description here

Published 376 original articles · praised 986 · 1.28 million views

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/105459630