springcouchbasecouchbase-java-api

How to limit Couchbase client from trying to connect to Couchbase server when it's down?


I'm trying to handle Couchbase bootstrap failure gracefully and not fail the application startup. The idea is to use "Couchbase as a service", so that if I can't connect to it, I should still be able to return a degraded response. I've been able to somewhat achieve this by using the Couchbase async API; RxJava FTW.

Problem is, when the server is down, the Couchbase Java client goes crazy and keeps trying to connect to the server; from what I see, the class that does this is ConfigEndpoint and there's no limit to how many times it tries before giving up. This is flooding the logs with java.net.ConnectException: Connection refused errors. What I'd like, is for it to try a few times, and then stop.

Got any ideas that can help?

Edit:

Here's a sample app.

Steps to reproduce the problem:

  1. svn export https://github.com/asarkar/spring/trunk/beer-demo.
  2. From the beer-demo directory, run ./gradlew bootRun. Wait for the application to start up.
  3. From another console, run curl -H "Accept: application/json" "http://localhost:8080/beers". The client request is going to timeout due to the failure to connect to Couchbase, but Couchbase client is going to flood the console continuously.

Solution

  • Solved this issue myself. The client I designed handles the following use cases:

    1. The client startup must be resilient of CB failure/availability.
    2. The client must not fail the request, but return a degraded response instead, if CB is not available.
    3. The client must reconnect should a CB failover happens.

    I've created a blog post here. I understand it's preferable to copy-paste rather than linking to an external URL, but the content is too big for an SO answer.