0%

influxdb客户端连接超时问题

问题

// 默认情况,java客户端连接服务端等待数据返回的时间很短,如果超时就会报以下错误
org.influxdb.InfluxDBIOException: java.net.SocketTimeoutException: timeout

解决办法

  • java

    OkHttpClient.Builder client = new OkHttpClient.Builder()
          .connectTimeout(1, TimeUnit.MINUTES)
          .readTimeout(1, TimeUnit.MINUTES)
          .writeTimeout(1, TimeUnit.MINUTES)
          .retryOnConnectionFailure(true);
    InfluxDB influxdb = InfluxDBFactory.connect("http://localhost:8086", client);
  • Scala

    val client = OkHttpClient.Builder()
          .connectTimeout(1, TimeUnit.MINUTES)
          .readTimeout(1, TimeUnit.MINUTES)
          .writeTimeout(1, TimeUnit.MINUTES)
          .retryOnConnectionFailure(true)
    val influxConnection = InfluxDBFactory.connect("http://localhost:8086", client)

参考链接