Issues connecting the Java SDK correctly


I’m having serious issues connecting to our Couchbase Server (4.5) with the Java SDK.
The story so far: I’m running couchbase inside of docker. I’ve opened up the couchbase ports like this:

port mappings
  • “8091:8091”
  • “8092:8092”
  • “8094:8093” <- notice the skip of 8093, as it’s currently used for something else and I can’t change that
  • “8095:8094”
  • “11210:11210”

I’m trying to connect via the Java SDK (using version 2.3.6 as it’s mentioned in the documentation) inside of a Spring Boot Application.
The connection itself works fine with

java connection build up
Cluster cluster = CouchbaseCluster.create(config.getHost());
Bucket bucket = cluster.openBucket("default","");

I can successfully load documents via bucket.get(“id”), which works via the 11210 port I assume. But the sdk fails to be able to even run the simplest query. bucket.query(N1qlQuery.simple(select("*").fromCurrentBucket())) fails with

com.couchbase.client.core.RequestCancelledException: Request cancelled in-flight.
	at com.couchbase.client.core.endpoint.AbstractGenericHandler.handleOutstandingOperations(
	at com.couchbase.client.core.endpoint.AbstractGenericHandler.exceptionCaught(

I do have a primary index on the bucket and querying via the Couchbase Web Console works fine.

My guess is, that it’s due to the changed port mapping, especially the query port 8093.
However, I couldn’t find any way to configure the port via the DefaultCouchbaseEnvironment.Builder() (as it was possible with e.g. the sdk version 2.2.7.) I also tried to go with the latest version 2.5.3, but get a cryptic exception:

2.5.3 - index out of bounds
2017-12-14 12:08:53.034  WARN 53923 --- [      cb-io-1-2] c.c.c.c.e.ResponseStatusConverter        : Unknown ResponseStatus with Protocol HTTP: 999
com.couchbase.client.core.CouchbaseException: java.lang.IndexOutOfBoundsException: readerIndex(0) + length(1) exceeds writerIndex(0): PooledUnsafeDirectByteBuf(ridx: 0, widx: 0, cap: 256)
	at com.couchbase.client.core.endpoint.AbstractGenericHandler.decode(

Please, can you give me any guidance on

  • which sdk version I can use with Couchbase 4.5 where I have full control over the port mappings
  • how to configure the couchbase sdk correctly, so the ports match and N1QL Queries work

Any help is appreciated. :slight_smile:

Best regards,
Norbert Spiess

Hello Norbert,

actually its the other way round. The SDK does not configure those ports at all, it gets this information from the cluster once it bootstraps properly and fetches a full configuration.

Check out the section on user defined ports here

So I guess with my docker setup (couchbase and spring boot in separate containers) the sdk would connect to the host, as the main port is available (11210). But from then on it assumes that the other ports are on their defaults, although they’re actually not due to the docker mapping.

Ok, so I guess I have two possibilities:

  • manage to free 8093 to get all default values for the couchbase ports
  • provide the static_config and adapt the mappings to that

Thanks for the explanation

Yes - if you can stick with the defaults its not fun to manage the custom ports in the long run I think

Just for the sake of further information… which ports are relevant for the sdk?

If I see the list here: I’d assume that 8092-8094 and 11210 are not the only ones…

8091-8094 (or 8095 if you count the new analytics in preview) as well as 11210. These are used if you don’t use encryption. If you use TLS its 18091 - 18094 (18095) and 11207 (instead of 11210).

8091 (18091): management
8092: (18092) views
8093 (18093): n1ql/query
8094 (18094): search
8095 (18095): analytics
11210 (11207): keyvalue

Note that there is a heap of other ports the cluster inernally needs for communication between the services which you need to expose as well depending on how you setup your cloud infra)

1 Like