38 lines
1.5 KiB
Java
38 lines
1.5 KiB
Java
package com.zdjizhi.source;
|
|
|
|
|
|
|
|
import com.zdjizhi.common.FlowWriteConfig;
|
|
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
|
|
*/
|
|
public class DosSketchSource {
|
|
|
|
private static StreamExecutionEnvironment streamExeEnv = FlinkEnvironmentUtils.streamExeEnv;
|
|
|
|
public static DataStreamSource<String> createDosSketchSource(){
|
|
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+"\";");
|
|
}
|
|
|
|
return streamExeEnv.addSource(new FlinkKafkaConsumer<String>(
|
|
FlowWriteConfig.KAFKA_INPUT_TOPIC_NAME,
|
|
new SimpleStringSchema(), properties))
|
|
.setParallelism(FlowWriteConfig.KAFKA_INPUT_PARALLELISM);
|
|
}
|
|
|
|
}
|