influxdb issues

org.influxdb.InfluxDBIOException: java.net.SocketTimeoutException: timeout

使用influxdb的java客户端连接influxdb:

1
InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:8086");

报错:

1
2
3
Exception in thread "main" org.influxdb.InfluxDBIOException: java.net.SocketTimeoutException: timeout
at org.influxdb.impl.InfluxDBImpl.execute(InfluxDBImpl.java:800)
at org.influxdb.impl.InfluxDBImpl.write(InfluxDBImpl.java:455)

更改OKHttpClient的默认超时:

1
2
3
4
5
6
OkHttpClient.Builder client = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(2, TimeUnit.MINUTES)
.retryOnConnectionFailure(true);
InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:8086", client);

参考:
https://github.com/influxdata/influxdb-java
https://stackoverflow.com/questions/50922473/influxdbioexception-java-net-sockettimeoutexception-timeout