Browse Source

集成apollo

hph_优化版本
1049970895@qniao.cn 3 years ago
parent
commit
1f1cd16916
6 changed files with 59 additions and 5 deletions
  1. 12
      root-cloud-statistics/pom.xml
  2. 13
      root-cloud-statistics/src/main/java/com/qniao/iot/rc/RootCloudIotDataFormatterJob.java
  3. 19
      root-cloud-statistics/src/main/java/com/qniao/iot/rc/config/ApolloConfig.java
  4. 14
      root-cloud-statistics/src/main/java/com/qniao/iot/rc/constant/ConfigConstant.java
  5. 3
      root-cloud-statistics/src/main/resources/META-INF/app.properties
  6. 3
      root-cloud-statistics/target/classes/META-INF/app.properties

12
root-cloud-statistics/pom.xml

@ -134,6 +134,18 @@ under the License.
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<!-- apollo -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-core</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
<build>

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

@ -18,7 +18,10 @@
package com.qniao.iot.rc;
import com.ctrip.framework.apollo.ConfigService;
import com.qniao.iot.machine.event.MachineIotDataReceivedEvent;
import com.qniao.iot.rc.config.ApolloConfig;
import com.qniao.iot.rc.constant.ConfigConstant;
import com.qniao.iot.rc.constant.DataSource;
import com.qniao.iot.rc.event.MachineIotDataReceivedEventSerializationSchema;
import com.qniao.iot.rc.event.RootCloudIotDataReceiptedEventDeserializationSchema;
@ -61,9 +64,9 @@ public class RootCloudIotDataFormatterJob {
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(60000L, CheckpointingMode.EXACTLY_ONCE);
KafkaSource<RootCloudIotDataReceiptedEvent> source = KafkaSource.<RootCloudIotDataReceiptedEvent>builder()
.setBootstrapServers(params.get("source.bootstrap.servers"))
.setTopics("root_cloud_iot_report_data_event")
.setGroupId("root_cloud_iot_data_etl")
.setBootstrapServers(ApolloConfig.get(ConfigConstant.SOURCE_KAFKA_BOOTSTRAP_SERVERS))
.setTopics(ApolloConfig.get(ConfigConstant.SOURCE_KAFKA_TOPICS))
.setGroupId(ApolloConfig.get(ConfigConstant.SOURCE_KAFKA_GROUPID))
.setStartingOffsets(OffsetsInitializer.earliest())
.setValueOnlyDeserializer(new RootCloudIotDataReceiptedEventDeserializationSchema())
.build();
@ -77,10 +80,10 @@ public class RootCloudIotDataFormatterJob {
// 写入kafka
transformDs.sinkTo(
KafkaSink.<MachineIotDataReceivedEvent>builder()
.setBootstrapServers(params.get("sink.bootstrap.servers"))
.setBootstrapServers(ApolloConfig.get(ConfigConstant.SINK_KAFKA_BOOTSTRAP_SERVERS))
.setRecordSerializer(
KafkaRecordSerializationSchema.builder()
.setTopic("machine_iot_data_received_event")
.setTopic(ApolloConfig.get(ConfigConstant.SINK_KAFKA_TOPICS))
.setValueSerializationSchema(new MachineIotDataReceivedEventSerializationSchema())
.build()
).setDeliverGuarantee(DeliveryGuarantee.AT_LEAST_ONCE)

19
root-cloud-statistics/src/main/java/com/qniao/iot/rc/config/ApolloConfig.java

@ -0,0 +1,19 @@
package com.qniao.iot.rc.config;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
public class ApolloConfig {
private static final Config config = ConfigService.getAppConfig();
public static String get(String key, String defaultValue) {
return config.getProperty(key, defaultValue);
}
public static String get(String key) {
return config.getProperty(key, null);
}
}

14
root-cloud-statistics/src/main/java/com/qniao/iot/rc/constant/ConfigConstant.java

@ -0,0 +1,14 @@
package com.qniao.iot.rc.constant;
public interface ConfigConstant {
String SOURCE_KAFKA_BOOTSTRAP_SERVERS = "source.kafka.bootstrap.servers";
String SOURCE_KAFKA_TOPICS = "source.kafka.topics";
String SOURCE_KAFKA_GROUPID = "source.kafka.groupId";
String SINK_KAFKA_BOOTSTRAP_SERVERS = "sink.kafka.bootstrap.servers";
String SINK_KAFKA_TOPICS = "sink.kafka.topics";
}

3
root-cloud-statistics/src/main/resources/META-INF/app.properties

@ -0,0 +1,3 @@
app.id=iot-root-cloud-model-hw-formatter
apollo.meta=http://8.135.8.221:5000

3
root-cloud-statistics/target/classes/META-INF/app.properties

@ -0,0 +1,3 @@
app.id=ztb-supply-chain-service
apollo.meta=http://8.135.8.221:5000
Loading…
Cancel
Save