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:
svn export https://github.com/asarkar/spring/trunk/beer-demo
.beer-demo
directory, run ./gradlew bootRun
. Wait for the application to start up.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.Solved this issue myself. The client I designed handles the following use cases:
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.