提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.influxdb.common.config; |
H |
2 |
|
|
3 |
import com.influxdb.client.InfluxDBClient; |
|
4 |
import com.influxdb.client.InfluxDBClientFactory; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
import org.springframework.beans.factory.annotation.Value; |
|
8 |
import org.springframework.stereotype.Component; |
|
9 |
|
|
10 |
/** |
|
11 |
* @author PanZhibao |
|
12 |
* @Description |
|
13 |
* @createTime 2023年04月25日 17:13:00 |
|
14 |
*/ |
|
15 |
@Component |
|
16 |
public class InfluxDBInstance { |
|
17 |
|
|
18 |
@Value("${influx-db.org}") |
|
19 |
public String org; |
|
20 |
|
|
21 |
@Value("${influx-db.bucket}") |
|
22 |
public String bucket; |
|
23 |
|
|
24 |
@Value("${influx-db.token}") |
|
25 |
public String token; |
|
26 |
|
|
27 |
@Value("${influx-db.url}") |
|
28 |
public String url; |
|
29 |
|
|
30 |
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
31 |
|
|
32 |
private InfluxDBClient client; |
|
33 |
|
|
34 |
public InfluxDBClient getClient() { |
|
35 |
try { |
|
36 |
if (client == null) { |
|
37 |
client = InfluxDBClientFactory.create(url, token.toCharArray()); |
|
38 |
} |
|
39 |
} catch (Exception ex) { |
|
40 |
ex.printStackTrace(); |
|
41 |
logger.error("创建InfluxDBClient失败!"); |
|
42 |
} |
|
43 |
return client; |
|
44 |
} |
|
45 |
|
0fbd01
|
46 |
|
a6de49
|
47 |
} |