Currently it's not possible to use Spring Boot's Couchbase auto configuration when running Couchbase locally in docker. This is because the Couchbase SDK does not accept alternative service ports in the connection string, a different API is to be used instead.
See Documentation here: https://docs.couchbase.com/java-sdk/current/howtos/managing-connections.html#alternate-addresses
I propose that new properties be added to org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties
private List<SeedNode> seedNodes = new ArrayList<>();
....
public static class SeedNode {
private String address;
private Integer kvPort;
private Integer clusterManagerPort;
}
So the configuration looks something like this:
spring.couchbase.seed-nodes[0].address=localhost
spring.couchbase.seed-nodes[0].kv-port=12345
spring.couchbase.seed-nodes[0].cluster-manager-port=54321
And then org.springframework.boot.autoconfigure.couchbase#couchbaseCluster
can be modified something like this:
ClusterOptions options = ClusterOptions.clusterOptions(properties.getUsername(), properties.getPassword())
.environment(couchbaseClusterEnvironment);
if (properties.getSeedNodes().isEmpty()) {
return Cluster.connect(properties.getConnectionString(), options);
} else {
Set<SeedNode> seedNodes = properties.getSeedNodes()
.stream()
.map(s -> SeedNode.create(s.getAddress(), Optional.ofNullable(s.getKvPort()), Optional.ofNullable(s.getClusterManagerPort())))
.collect(Collectors.toSet());
return Cluster.connect(seedNodes, options);
}
Comment From: wilkinsona
Thanks for the suggestion.
This looks like a good addition to me. We'd need to be careful when having both a connectionString
and some seed nodes as only one can take effect. I think the seed nodes winning (as you have done above) is the right thing to do, so we'd just need to document that behaviour in the property descriptions.
Would you like to turn what you've sketched out above into a pull request?
Comment From: wilkinsona
Thanks for opening a PR, @aaronjwhiteside! This issue is now superseded by #25005.