refactor: store runtime identity and mileage in mysql metrics
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.lingniu.ingest.identity.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lingniu.ingest.identity.FileVehicleIdentityService;
|
||||
import com.lingniu.ingest.identity.InMemoryVehicleIdentityService;
|
||||
import com.lingniu.ingest.identity.MySqlVehicleIdentityService;
|
||||
import com.lingniu.ingest.identity.VehicleIdentityRegistry;
|
||||
import com.lingniu.ingest.identity.VehicleIdentityResolver;
|
||||
@@ -14,7 +12,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(VehicleIdentityProperties.class)
|
||||
@@ -28,16 +25,8 @@ public class VehicleIdentityAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({VehicleIdentityResolver.class, VehicleIdentityRegistry.class})
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.identity", name = "store", havingValue = "file")
|
||||
public FileVehicleIdentityService fileVehicleIdentityService(VehicleIdentityProperties properties,
|
||||
ObjectMapper objectMapper) {
|
||||
// 文件实现同时提供 resolver 和 registry,协议层既能查绑定,也能在注册/鉴权时补写绑定。
|
||||
return new FileVehicleIdentityService(Path.of(properties.getFile().getPath()), objectMapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({VehicleIdentityResolver.class, VehicleIdentityRegistry.class})
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.identity", name = "store", havingValue = "mysql")
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.identity", name = "store", havingValue = "mysql",
|
||||
matchIfMissing = true)
|
||||
public MySqlVehicleIdentityService mysqlVehicleIdentityService(VehicleIdentityProperties properties,
|
||||
ObjectMapper objectMapper) {
|
||||
VehicleIdentityProperties.Mysql mysql = properties.getMysql();
|
||||
@@ -45,12 +34,4 @@ public class VehicleIdentityAutoConfiguration {
|
||||
mysql.getJdbcUrl(), mysql.getUsername(), mysql.getPassword());
|
||||
return new MySqlVehicleIdentityService(dataSource, mysql, objectMapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({VehicleIdentityResolver.class, VehicleIdentityRegistry.class})
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.identity", name = "store", havingValue = "memory",
|
||||
matchIfMissing = true)
|
||||
public InMemoryVehicleIdentityService vehicleIdentityService() {
|
||||
return new InMemoryVehicleIdentityService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,24 +5,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@ConfigurationProperties(prefix = "lingniu.ingest.identity")
|
||||
public class VehicleIdentityProperties {
|
||||
|
||||
private String store = "memory";
|
||||
private File file = new File();
|
||||
private String store = "mysql";
|
||||
private Mysql mysql = new Mysql();
|
||||
|
||||
public String getStore() { return store; }
|
||||
public void setStore(String store) { this.store = store; }
|
||||
public File getFile() { return file; }
|
||||
public void setFile(File file) { this.file = file; }
|
||||
public Mysql getMysql() { return mysql; }
|
||||
public void setMysql(Mysql mysql) { this.mysql = mysql; }
|
||||
|
||||
public static class File {
|
||||
private String path = "./data/vehicle-identity.jsonl";
|
||||
|
||||
public String getPath() { return path; }
|
||||
public void setPath(String path) { this.path = path; }
|
||||
}
|
||||
|
||||
public static class Mysql {
|
||||
private String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/lingniu_vehicle?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai";
|
||||
private String username = "root";
|
||||
|
||||
Reference in New Issue
Block a user