Creating a FlinkServer Job to Write Data to a DWS
This section applies to MRS 3.3.1 and later.
Scenario
Data Warehouse Service (DWS) is an online data analysis and processing database. This topic uses the FlinkServer and Kafka in security mode, and takes DWS as the sink table to explain the "with" parameters for creating a table and code examples. You will learn how to interconnect with DWS on the FlinkServer job management page.
When "FlinkSQL" is displayed in the command output on the FlinkServer web UI in MRS 3.2.0 or later clusters, the password field in the SQL statement is left blank. Before you submit a job, manually enter the password.
Prerequisites
- HDFS, Yarn, Kafka, ZooKeeper, and Flink have been installed.
- The client that contains the Kafka service has been installed, for example, in the /opt/client directory.
- You have created a user with the FlinkServer Admin Privilege (for example, flinkuser) for accessing the Flink web UI by referring to Creating a FlinkServer Role.
Procedure
- Create an empty table for receiving data in a DWS database, for example, dws_test.
- Log in to Manager as user flinkuser and choose Cluster > Services > Flink. In the Basic Information area, click the link next to Flink WebUI to access the Flink web UI.
- Create a Flink SQL job by referring to Creating a FlinkServer Job. On the job development page, configure the job parameters as follows and start the job.
In Basic Parameter, select Enable CheckPoint, set Time Interval(ms) to 60000, and retain the default value for Mode.
CREATE TABLE dws_test( c_customer_sk INTEGER, c_customer_name VARCHAR(32) ) WITH( 'connector' = 'dws', 'url' = 'jdbc:postgresql://DWS connection address/gaussdb', 'table-name' = 'dws_test', 'username' ='DWS username', 'password' ='DWS user password' ); CREATE TABLE KafkaSource ( c_customer_sk INTEGER, c_customer_name VARCHAR(32) ) WITH ( 'connector' = 'kafka', 'topic' = 'customer_source', 'properties.bootstrap.servers' = 'Service IP address of the Kafka Broker instance:Kafka port', 'properties.group.id' = 'testGroup', 'scan.startup.mode' = 'latest-offset', 'value.format' = 'csv', 'properties.sasl.kerberos.service.name' = 'kafka', --Delete this parameter if the cluster where FlinkServer is deployed is in non-security mode. 'properties.security.protocol' = 'SASL_PLAINTEXT', --Delete this parameter if the cluster where FlinkServer is deployed is in non-security mode. 'properties.kerberos.domain.name' = 'hadoop.System domain name' --Delete this parameter if the cluster where FlinkServer is deployed is in non-security mode. ); Insert into dws_test select * from KafkaSource;
- The IP address and port number of the Kafka broker instance are as follows:
- To obtain the instance IP address, log in to FusionInsight Manager, choose Cluster > Services > Kafka, click Instance, and query the instance IP address on the instance list page.
- If Kerberos authentication is enabled for the cluster (the cluster is in security mode), the Broker port number is the value of sasl.port. The default value is 21007.
- If Kerberos authentication is disabled for the cluster (the cluster is in normal mode), the broker port number is the value of port. The default value is 9092. If the port number is set to 9092, set allow.everyone.if.no.acl.found to true. The procedure is as follows:
Log in to FusionInsight Manager and choose Cluster > Services > Kafka. Click Configurations then All Configurations. On the page that is displayed, search for allow.everyone.if.no.acl.found, set it to true, and click Save.
- System domain name: To obtain the value, log in to FusionInsight Manager, choose System > Permission > Domain and Mutual Trust, and check the value of Local Domain.
- properties.group.id indicates the Kafka user group ID. This parameter is mandatory when Kafka functions as the source.
- properties.kerberos.domain.name: Set it to hadoop.System domain name. To obtain the actual domain name of the cluster, log in to FusionInsight Manager and choose System > Permission > Domain and Mutual Trust.
- The DWS sink supports the configuration of batch parameters. When one of the conditions is met, the sink is triggered.
- autoFlushBatchSize: size of the batch for automatically refreshing the database. Default value: 5000.
- autoFlushMaxInterval: maximum interval for automatically refreshing the database (duration to form a batch). Default value: 5s.
- The IP address and port number of the Kafka broker instance are as follows:
- On the job management page, check whether the job status is Running.
- Execute the following commands to view the topic and write data to Kafka. For details, see Managing Messages in Kafka Topics.
./kafka-topics.sh --list --bootstrap-server Service IP address of the Kafka Broker instance:Kafka port --command-config Client directory/Kafka/kafka/config/client.properties
sh kafka-console-producer.sh --broker-list IP address of the node where Kafka Broker instances reside:Kafka port --topic Topic name --producer.config Client directory/Kafka/kafka/config/producer.properties
In this example, the topic name is customer_source.
sh kafka-console-producer.sh --broker-list IP address of the node where the Kafka Broker instance is located:Kafka port --topic customer_source --producer.config /opt/client/Kafka/kafka/config/producer.properties
Enter the message content.
3,zhangsan 4,wangwu 8,zhaosi
Press Enter to send the message.
- Log in to the DWS client and run the following command to check whether the sink table received data:
Select * from dws_test;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot