2021-07-29 10:02:31 +08:00
|
|
|
package com.zdjizhi.source;
|
|
|
|
|
|
|
|
|
|
import com.zdjizhi.common.CommonConfig;
|
2022-11-23 15:30:24 +08:00
|
|
|
import com.zdjizhi.common.CustomFile;
|
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;
|
|
|
|
|
|
2022-11-23 15:30:24 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2021-07-29 10:02:31 +08:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
2021-08-16 18:24:13 +08:00
|
|
|
/**
|
|
|
|
|
* @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", CommonConfig.KAFKA_INPUT_BOOTSTRAP_SERVERS);
|
|
|
|
|
properties.setProperty("group.id", CommonConfig.KAFKA_GROUP_ID);
|
2021-09-14 18:46:23 +08:00
|
|
|
if (CommonConfig.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=\""+CommonConfig.SASL_JAAS_CONFIG_USER+"\" password=\""+CommonConfig.SASL_JAAS_CONFIG_PASSWORD+"\";");
|
|
|
|
|
}
|
2021-07-29 10:02:31 +08:00
|
|
|
|
|
|
|
|
return streamExeEnv.addSource(new FlinkKafkaConsumer<String>(
|
|
|
|
|
CommonConfig.KAFKA_INPUT_TOPIC_NAME,
|
|
|
|
|
new SimpleStringSchema(), properties))
|
|
|
|
|
.setParallelism(CommonConfig.KAFKA_INPUT_PARALLELISM);
|
|
|
|
|
}
|
2022-11-23 15:30:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public static DataStreamSource<Map<String, byte[]>> broadcastSource(Properties nacosProperties, String STORE_PATH){
|
|
|
|
|
return streamExeEnv.addSource(new HttpSource(nacosProperties, CommonConfig.NACOS_DATA_ID, CommonConfig.NACOS_GROUP, CommonConfig.NACOS_READ_TIMEOUT,STORE_PATH));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DataStreamSource<Map<String, byte[]>> singleBroadcastSource(Properties nacosProperties){
|
|
|
|
|
return streamExeEnv.addSource(new SingleHttpSource(nacosProperties, CommonConfig.NACOS_DATA_ID, CommonConfig.NACOS_GROUP, CommonConfig.NACOS_READ_TIMEOUT));
|
|
|
|
|
}
|
2021-07-29 10:02:31 +08:00
|
|
|
}
|