Browse Source

更新

hph_优化版本
1049970895@qniao.cn 3 years ago
parent
commit
fdeb21bb1b
2 changed files with 28 additions and 13 deletions
  1. 17
      root-cloud-statistics/pom.xml
  2. 24
      root-cloud-statistics/src/main/java/com/qniao/iot/rc/RootCloudIotDataFormatterJob.java

17
root-cloud-statistics/pom.xml

@ -88,6 +88,12 @@ under the License.
<version>${log4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!--<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@ -126,8 +132,7 @@ under the License.
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-elasticsearch7_2.11</artifactId>
<version>1.13.0</version>
<scope>compile</scope>
<version>1.14.5</version>
</dependency>
</dependencies>
@ -193,4 +198,12 @@ under the License.
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus releases Repository</name>
<url>http://120.78.76.88:8081/repository/maven-snapshots/</url>
</repository>
</distributionManagement>
</project>

24
root-cloud-statistics/src/main/java/com/qniao/iot/rc/RootCloudIotDataFormatterJob.java

@ -128,8 +128,8 @@ public class RootCloudIotDataFormatterJob {
Integer deviceStatus = getDeviceStatus(event);
DeviceState newState = new DeviceState(event.getId(), event.getMachineIotMac(), deviceStatus, event.getReportTime());
collDeviceStatusChange(out, newState, null, event);
/*DeviceState newState = new DeviceState(event.getId(), event.getMachineIotMac(), deviceStatus, event.getReportTime());
collDeviceStatusChange(out, newState, null, event);*/
if (deviceStatus == null) {
out.collect(null);
@ -139,10 +139,10 @@ public class RootCloudIotDataFormatterJob {
deviceState.update(new DeviceState(event.getId(), event.getMachineIotMac(), deviceStatus, event.getReportTime()));
System.out.println("初始化设备状态" + deviceState.value().toString());
} else {
/*DeviceState newState = new DeviceState(event.getId(), event.getMachineIotMac(), deviceStatus, event.getReportTime());
DeviceState newState = new DeviceState(event.getId(), event.getMachineIotMac(), deviceStatus, event.getReportTime());
DeviceState oldState = deviceState.value();
collDeviceStatusChange(out, newState, oldState, event);
deviceState.update(newState);*/
deviceState.update(newState);
}
}
}
@ -150,13 +150,19 @@ public class RootCloudIotDataFormatterJob {
// 写入rabbitmq
// sinkRabbitMq(commandDataStream);
sinkRabbitMq(commandDataStream);
// 写入es
sinkEs(commandDataStream);
env.execute("Kafka Job");
}
private static void sinkEs(DataStream<BaseCommand> commandDataStream) {
List<HttpHost> httpHosts = new ArrayList<>();
httpHosts.add(new HttpHost("119.23.41.137", 9200, "http"));
ElasticsearchSink.Builder<BaseCommand> esSinkBuilder = new ElasticsearchSink.Builder<>(
httpHosts,
ElasticsearchSink.Builder<BaseCommand> esSinkBuilder = new ElasticsearchSink.Builder<>(httpHosts,
(ElasticsearchSinkFunction<BaseCommand>) (command, runtimeContext, requestIndexer) -> {
HashMap<String, String> map = new HashMap<>();
@ -164,14 +170,12 @@ public class RootCloudIotDataFormatterJob {
PowerOnMachineCommand powerOnMachineCommand = (PowerOnMachineCommand)command;
map.put("id", powerOnMachineCommand.getId().toString());
map.put("currTotalOutput", powerOnMachineCommand.getCurrTotalOutput().toString());
map.put("timestamp", powerOnMachineCommand.getTimestamp().toString());
}
if(command instanceof PowerOffMachineCommand) {
PowerOffMachineCommand powerOffMachineCommand = (PowerOffMachineCommand)command;
map.put("id", powerOffMachineCommand.getId().toString());
map.put("currTotalOutput", powerOffMachineCommand.getCurrTotalOutput().toString());
map.put("timestamp", powerOffMachineCommand.getTimestamp().toString());
}
//创建es 请求
IndexRequest indexRequest = Requests.indexRequest().index("flink").source(map);
@ -195,8 +199,6 @@ public class RootCloudIotDataFormatterJob {
);
//数据流添加sink
commandDataStream.addSink(esSinkBuilder.build()).name("BaseCommand sink");
env.execute("Kafka Job");
}
private static void sinkRabbitMq(DataStream<BaseCommand> commandDataStream) {

Loading…
Cancel
Save