5

I'm looking for a way to use Spring Data Couchbase to connect to two separate Couchbase clusters. Looking at the documentation and the implementation, it is not clear as how to do this and my concern is that there will be bean name conflicts if have two configurations that extend AbstractCouchbaseConfiguration. The only thing that looks close is to use the RepositoryOperationsMapping to specify different templates for different repositories. This however doesn't suit my needs as each of the Couchbase configurations will not be aware of the other. The only means i see of doing this now is to either not use AbstractCouchbaseConfiguration and setup my own beans or to override all the beans in AbstractCouchbaseConfiguration and provide new bean names. In each case, i would override the couchbase template bean name in the @EnableCouchbaseRepositories annotation. However, i'm not sure if this is going to work or if there is a better option.

Is this possible and if so, what is the best route for me to take?

Thank you

loesak
  • 1,413
  • 2
  • 19
  • 33

1 Answers1

0

Could you elaborate on the use case that warranted the creation and connection to two separate clusters?

The best route here is still probably to define new Cluster, Bucket and CouchbaseTemplate beans, with custom names, in your existing AbstractCouchbaseConfiguration, and then use the configureRepositoryOperationsMapping() method in the conf. Basically like described in the doc about multiple buckets, but adding a second Cluster bean to the mix.

Simon Baslé
  • 27,105
  • 5
  • 69
  • 70
  • The use case is that there is a shared library that is used by multiple projects. This library provides a service that is backed by data in a configured CB cluster. The configuration of the beans used by the service is in the library itself. If one such project needs to use the library and itself needs to read/write data from a different CB cluster then, assuming that they both are using SD-CB, and they both have configurations that extend from AbstractCouchbaseConfiguration then there will be conflicts with bean names. – loesak Apr 18 '16 at 21:09