简体   繁体   中英

How to restore Couchbase database connection automatically in spring boot application?

I am using spring data Couchbase to connect to the Couchbase database from my spring boot application. And I am directly connecting to the Bucket using bucket name and password. But when there is any database maintenance(linux patching/db restart) then connection is getting break and it's not automatically restored when database maintenance is over. And I get "ConcurrentTimeout Exception". and I have to restart the application to connect to the database. Is there any setting/configuration that I can do to restore the connection automatically? version: spring-data-couchbase:2.2.20.release and Couchbase server: 6.6

The java SDK will only try to connect for the duration specified by the kv connect timeout. To try for up to one hour, modified the couchbase environment by overriding the configureEnvironment() method in AbstractCouchbaseConfiguration.

@Override
protected void configureEnvironment(ClusterEnvironment.Builder builder) {
    builder.timeoutConfig().connectTimeout(Duration.ofSeconds(3600));
}

In the 2.x SDK, I believe this would be DefaultCouchbaseEnvironment.builder().socketConnectTimeout()

https://docs.couchbase.com/sdk-api/couchbase-core-io-1.7.12/com/couchbase/client/core/env/DefaultCoreEnvironment.Builder.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM