Commit 35fc131f by 黄准

Merge remote-tracking branch 'origin/master'

# Conflicts: # realtime/hologram-streaming/src/main/java/com/zhht/irn/functions/LaneNormProcessFunction.java # realtime/hologram-streaming/src/main/java/com/zhht/irn/sink/LaneNormSink.java
parents 044bd9c9 1dc7a657
...@@ -6,9 +6,11 @@ import com.zhht.irn.entity.Stage; ...@@ -6,9 +6,11 @@ import com.zhht.irn.entity.Stage;
import com.zhht.irn.sink.GreenRadioSink; import com.zhht.irn.sink.GreenRadioSink;
import com.zhht.irn.utils.FlinkUtils; import com.zhht.irn.utils.FlinkUtils;
import org.apache.flink.api.common.functions.MapFunction; import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.datastream.DataStream; import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import java.net.URL;
import java.util.List; import java.util.List;
/** /**
...@@ -21,8 +23,10 @@ import java.util.List; ...@@ -21,8 +23,10 @@ import java.util.List;
public class GreenRadioJob { public class GreenRadioJob {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
ParameterTool kafkaTool = ParameterTool.fromArgs(args);
FlinkUtils.createKafkaStream(args, env) String topic = kafkaTool.get("kafka.input.topics");
System.out.println("***topic:"+topic);
FlinkUtils.createKafkaStream(args, env,topic,"GreenRadioJob")
.map(record -> { .map(record -> {
// 字符串解析为实体类 // 字符串解析为实体类
Cycle cycle = JSON.parseObject(record, Cycle.class); Cycle cycle = JSON.parseObject(record, Cycle.class);
......
...@@ -2,6 +2,7 @@ package com.zhht.irn.utils; ...@@ -2,6 +2,7 @@ package com.zhht.irn.utils;
import org.apache.flink.api.java.utils.ParameterTool; import org.apache.flink.api.java.utils.ParameterTool;
import java.io.InputStream;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
...@@ -10,12 +11,8 @@ import java.sql.SQLException; ...@@ -10,12 +11,8 @@ import java.sql.SQLException;
public class DorisUtils { public class DorisUtils {
public static Connection getConnection() throws Exception { public static Connection getConnection() throws Exception {
String propertyPath = ".\\realtime\\hologram-streaming\\src\\main\\resources\\doris.properties"; InputStream inputStream = DorisUtils.class.getClassLoader().getResourceAsStream("doris.properties");
return getConnection(propertyPath); ParameterTool tool = ParameterTool.fromPropertiesFile(inputStream);
}
public static Connection getConnection(String propertyPath) throws Exception {
ParameterTool tool = ParameterTool.fromPropertiesFile(propertyPath);
// 根据路径的配置文件获取MySQL链接参数 // 根据路径的配置文件获取MySQL链接参数
String driver = tool.getRequired("driver"); String driver = tool.getRequired("driver");
......
...@@ -11,10 +11,12 @@ import org.apache.flink.streaming.api.environment.CheckpointConfig; ...@@ -11,10 +11,12 @@ import org.apache.flink.streaming.api.environment.CheckpointConfig;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer; import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import org.apache.flink.streaming.connectors.kafka.KafkaDeserializationSchema; import org.apache.flink.streaming.connectors.kafka.KafkaDeserializationSchema;
import org.apache.flink.util.PropertiesUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
...@@ -43,10 +45,10 @@ public class FlinkUtils { ...@@ -43,10 +45,10 @@ public class FlinkUtils {
static { static {
// 获取Kafka配置文件, 直接读取当前程序目录下的 // 获取Kafka配置文件, 直接读取当前程序目录下的
String kafkaConfigPath = "kafka.properties";
ParameterTool kafkaTool; ParameterTool kafkaTool;
try { try {
kafkaTool = ParameterTool.fromPropertiesFile(kafkaConfigPath); InputStream inputStream = FlinkUtils.class.getClassLoader().getResourceAsStream("kafka.properties");
kafkaTool = ParameterTool.fromPropertiesFile(inputStream);
} catch (IOException e) { } catch (IOException e) {
logger.error("kafka 配置文件未设置,请检查!"); logger.error("kafka 配置文件未设置,请检查!");
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -3,21 +3,16 @@ package com.zhht.irn.utils; ...@@ -3,21 +3,16 @@ package com.zhht.irn.utils;
import org.apache.flink.api.java.utils.ParameterTool; import org.apache.flink.api.java.utils.ParameterTool;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
public class MySQLUtils { public class MySQLUtils {
public static Connection getConnection() throws Exception { public static Connection getConnection() throws Exception {
String propertyPath = ".\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties"; InputStream inputStream = DorisUtils.class.getClassLoader().getResourceAsStream("mysql.properties");
return getConnection(propertyPath); ParameterTool tool = ParameterTool.fromPropertiesFile(inputStream);
}
public static Connection getConnection(String propertyPath) throws Exception {
ParameterTool tool = ParameterTool.fromPropertiesFile(propertyPath);
// 根据路径的配置文件获取MySQL链接参数 // 根据路径的配置文件获取MySQL链接参数
String driver = tool.getRequired("driver"); String driver = tool.getRequired("driver");
String username = tool.getRequired("username"); String username = tool.getRequired("username");
...@@ -48,12 +43,4 @@ public class MySQLUtils { ...@@ -48,12 +43,4 @@ public class MySQLUtils {
} }
} }
} }
public static void main(String[] args) {
try {
System.out.println(getConnection("F:\\workspace\\ZHHT-IRN-BD-ANALYSIS\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment