This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
galaxy-tsg-olap-dos-detecti…/src/main/java/com/zdjizhi/source/DosSketchSource.java

38 lines
1.5 KiB
Java
Raw Normal View History

2021-07-29 10:02:31 +08:00
package com.zdjizhi.source;
import com.zdjizhi.common.FlowWriteConfig;
2021-07-29 10:02:31 +08:00
import com.zdjizhi.utils.FlinkEnvironmentUtils;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import java.util.Properties;
/**
* @author wlh
*/
2021-07-29 10:02:31 +08:00
public class DosSketchSource {
private static StreamExecutionEnvironment streamExeEnv = FlinkEnvironmentUtils.streamExeEnv;
2021-08-02 18:11:29 +08:00
public static DataStreamSource<String> createDosSketchSource(){
2021-07-29 10:02:31 +08:00
Properties properties = new Properties();
properties.setProperty("bootstrap.servers", FlowWriteConfig.KAFKA_INPUT_BOOTSTRAP_SERVERS);
properties.setProperty("group.id", FlowWriteConfig.KAFKA_GROUP_ID);
if (FlowWriteConfig.SASL_JAAS_CONFIG_FLAG == 1){
properties.put("security.protocol", "SASL_PLAINTEXT");
properties.put("sasl.mechanism", "PLAIN");
properties.put("sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\""+ FlowWriteConfig.SASL_JAAS_CONFIG_USER+"\" password=\""+ FlowWriteConfig.SASL_JAAS_CONFIG_PASSWORD+"\";");
}
2021-07-29 10:02:31 +08:00
return streamExeEnv.addSource(new FlinkKafkaConsumer<String>(
FlowWriteConfig.KAFKA_INPUT_TOPIC_NAME,
2021-07-29 10:02:31 +08:00
new SimpleStringSchema(), properties))
.setParallelism(FlowWriteConfig.KAFKA_INPUT_PARALLELISM);
}
2021-07-29 10:02:31 +08:00
}