3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BigQueryでsocket timeoutを回避したメモ

Last updated at Posted at 2015-12-28

JavaアプリケーションからBigQueryに対してInsertしているとたまにsocket timeoutでエラーになってしまうことがあったので対応内容の備忘録。

やったこと

GoogleCredential.BuilderのRequestInitializerでreadTimeoutを設定。

サンプルコード

    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory   jsonFactory   = new JacksonFactory();
    GoogleCredential.Builder credBuilder = new GoogleCredential.Builder();
    credBuilder.setJsonFactory(jsonFactory);
    credBuilder.setTransport(httpTransport);
    credBuilder.setServiceAccountId(ACCOUNT_ID);
    credBuilder.setServiceAccountPrivateKeyFromP12File(KEY_FILE);
    credBuilder.setServiceAccountScopes(Collections.singleton(BigqueryScopes.BIGQUERY));
    final HttpRequestInitializer initializer = credBuilder.getRequestInitializer();
    credBuilder.setRequestInitializer(new HttpRequestInitializer() {
        public void initialize(HttpRequest request) throws IOException {
            initializer.initialize(request);
            request.setReadTimeout(0); // milliseconds (0: infinity)
        }
    });
    GoogleCredential credential = credBuilder.build();
    :
    :

これとかみると NetHttpTransportでreadTimeoutを設定すれば良い気もしたけど、HttpTransportをNetHttpTransportに変えてもビルドエラーになってしまったのでとりあえずこれで回避。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?