influxDB java.net.SocketTimeoutException: Read timed out 问题

原因:由于http超时
1.声明 OkHttpClient 设置超时时间

static OkHttpClient.Builder client = new OkHttpClient.Builder()
            .readTimeout(100,TimeUnit.SECONDS);

2.在构造参数时传入

@SuppressWarnings("deprecation")
    public InfluxDB influxDbBuild() {
        try {
            if (influxDB == null) {
                if (openurl != null) {
                     //在这里传入
                    influxDB = InfluxDBFactory.connect(openurl, username, password,client);
                    if (influxDB != null) {
                        boolean flag = influxDB.databaseExists(keyDataBase);
                        if (!flag) {
                            influxDB.createDatabase(keyDataBase);
                            createKeyRetentionPolicy(); //初始化创建保存策略
                        }
                        flag = influxDB.databaseExists(rtDataBase);
                        if (!flag) {
                            influxDB.createDatabase(rtDataBase);
                            createRtRetentionPolicy(); //初始化创建保存策略
                        }
                        flag = influxDB.databaseExists(solvedDataBase);
                        if (!flag) {
                            influxDB.createDatabase(solvedDataBase);
                            createSolvedEventRetentionPolicy(); //初始化创建保存策略
                        }
                    }
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return influxDB;
    }

参考 https://github.com/influxdata/influxdb-java/issues/482

posted @ 2019-10-18 16:56  lin819747263  阅读(1832)  评论(0编辑  收藏  举报