Updated on 2022-09-14 GMT+08:00

Scenario

Scenario

Assume that a Flink service (service 1) receives a message every second. The message records the basic information about a user, including the name, gender, and age. Another Flink service (service 2) receives a message irregularly, and the message records the name and career information about the user.

To meet the requirements of some services, the Flink application is developed to achieve the following function: uses the username recorded in the message received by service 2 as the keyword to jointly query two pieces of service data.

Data Planning

  • The data of service 1 is stored in the Kafka component. Service 1 sends data (requiring Kafka user rights) to and receives data from the Kafka component. For details about how to configure Kafka, see the data planning section of Data Planning.
  • Service 2 receives messages using the socket. You can run the netcat command to input the analog data source.
    • Run the netcat -l -p <port> command to start a simple text server.
    • After starting the application to connect to the port monitored by netcat, enter the data information to the netcat terminal.

Development Approach

  1. Start the Flink Kafka Producer application to send data to Kafka.
  2. Start the Flink Kafka Consumer application to receive data from Kafka, construct Table1, and ensure that the Topic is the same as that of Producer.
  3. Read data from the socket and construct Table2.
  4. Use Flink SQL to query and print Table1 and Table2.