|
|
@@ -25,48 +25,31 @@ import java.util.stream.Collectors;
|
|
|
@EnableConfigurationProperties(InfluxDbProperties.class)
|
|
|
@PropertySource(value = "file:${global.sql-config-path}", ignoreResourceNotFound = true, encoding = "utf-8", factory = YamlPropertySourceFactory.class)
|
|
|
public class InfluxDbConfig {
|
|
|
- final
|
|
|
- OkHttpClient.Builder builder;
|
|
|
- final
|
|
|
- InfluxDbProperties influxDbProperties;
|
|
|
-
|
|
|
- public InfluxDbConfig(ObjectProvider<InfluxDbOkHttpClientBuilderProvider> builder
|
|
|
- , ObjectProvider<OkHttpClient.Builder> deprecatedBuilder, InfluxDbProperties influxDbProperties) {
|
|
|
- this.builder = determineBuilder(builder.getIfAvailable(),
|
|
|
- deprecatedBuilder.getIfAvailable());
|
|
|
- this.influxDbProperties = influxDbProperties;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 确认构建器
|
|
|
- *
|
|
|
- * @param builder 默认构建器
|
|
|
- * @param deprecatedBuilder 弃用构建器
|
|
|
- * @return 可使用的构建器
|
|
|
- */
|
|
|
- private static OkHttpClient.Builder determineBuilder(InfluxDbOkHttpClientBuilderProvider builder
|
|
|
- , OkHttpClient.Builder deprecatedBuilder) {
|
|
|
- return builder != null ? builder.get()
|
|
|
- : deprecatedBuilder != null ? deprecatedBuilder
|
|
|
- : new OkHttpClient.Builder();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* influxDb注册器
|
|
|
*
|
|
|
+ * @param properties 属性
|
|
|
+ * @param providers 构建器提供
|
|
|
* @return influxDb注册器
|
|
|
*/
|
|
|
@Bean
|
|
|
- public InfluxDBClients influxDBClients() {
|
|
|
- this.builder.readTimeout(influxDbProperties.getReadTimeout());
|
|
|
+ public InfluxDBClients influxDBClients(InfluxDbProperties properties, ObjectProvider<InfluxDbOkHttpClientBuilderProvider> providers) {
|
|
|
+ //构建器
|
|
|
+ OkHttpClient.Builder builder = determineBuilder(providers.getIfAvailable());
|
|
|
+ builder.readTimeout(properties.getReadTimeout());
|
|
|
//客户端集合
|
|
|
- List<InfluxDbClient> clients = influxDbProperties.getClients().stream()
|
|
|
+ List<InfluxDbClient> clients = properties.getClients().stream()
|
|
|
.map(client -> new InfluxDbClient(client.getUrl(), client.getUser(), client.getPassword()
|
|
|
- , client.getDatabase(), this.builder))
|
|
|
+ , client.getDatabase(), builder))
|
|
|
.collect(Collectors.toList());
|
|
|
//注册
|
|
|
return InfluxDBClients.builder()
|
|
|
.addClients(clients)
|
|
|
.build();
|
|
|
}
|
|
|
+
|
|
|
+ private OkHttpClient.Builder determineBuilder(InfluxDbOkHttpClientBuilderProvider builder) {
|
|
|
+ if (builder != null) return builder.get();
|
|
|
+ return new OkHttpClient.Builder();
|
|
|
+ }
|
|
|
}
|