-
Notifications
You must be signed in to change notification settings - Fork 192
Missing couchbase.repository.multibucket documentation (4.x) [DATACOUCH-570] #878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Michael Reiche commented Hi Guillaume DURANDIERE - that section will be added shortly. In the mean time, to leverage multi-bucket repositories, implement the methods below in your Config class. The config*OperationsMapping methods configure the mapping of entity-objects to buckets. Be careful with the method names - using a method name that is a Bean will result in the value of that bean being used instead of the result of the method. This example maps Person -> protected, User -> mybucket, and everything else goes to getBucketName(). Note that this only maps calls through the Repository. @Override
public void configureReactiveRepositoryOperationsMapping(ReactiveRepositoryOperationsMapping baseMapping) {
try {
ReactiveCouchbaseTemplate personTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("protected"),new MappingCouchbaseConverter());
baseMapping.mapEntity(Person.class, personTemplate); // Person goes in "protected" bucket
ReactiveCouchbaseTemplate userTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter());
baseMapping.mapEntity(User.class, userTemplate); // User goes in "mybucket"
// everything else goes in getBucketName()
} catch (Exception e) {
throw e;
}
}
@Override
public void configureRepositoryOperationsMapping(RepositoryOperationsMapping baseMapping) {
try {
CouchbaseTemplate personTemplate = myCouchbaseTemplate(myCouchbaseClientFactory("protected"),new MappingCouchbaseConverter());
baseMapping.mapEntity(Person.class, personTemplate); // Person goes in "protected" bucket
CouchbaseTemplate userTemplate = myCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter());
baseMapping.mapEntity(User.class, userTemplate); // User goes in "mybucket"
// everything else goes in getBucketName()
} catch (Exception e) {
throw e;
}
}
// do not use reactiveCouchbaseTemplate for the name of this method, otherwise the value of that bean
// will be used instead of the result of this call (the client factory arg is different)
public ReactiveCouchbaseTemplate myReactiveCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
MappingCouchbaseConverter mappingCouchbaseConverter) {
return new ReactiveCouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter);
}
// do not use couchbaseTemplate for the name of this method, otherwise the value of that been
// will be used instead of the result from this call (the client factory arg is different)
public CouchbaseTemplate myCouchbaseTemplate(CouchbaseClientFactory couchbaseClientFactory,
MappingCouchbaseConverter mappingCouchbaseConverter) {
return new CouchbaseTemplate(couchbaseClientFactory, mappingCouchbaseConverter);
}
// do not use couchbaseClientFactory for the name of this method, otherwise the value of that bean will
// will be used instead of this call being made ( bucketname is an arg here, instead of using bucketName() )
public CouchbaseClientFactory myCouchbaseClientFactory(String bucketName) {
return new SimpleCouchbaseClientFactory(getConnectionString(),authenticator(), bucketName );
} |
Guillaume Durandiere commented Thanks for your answer! I will try it. |
ohjongsung commented same issue documentation (4.0.2) |
arana3 commented
The instructions you provided do not work. This is because in the latest 4.x Spring Data Couchbase, the mapEntity method requires the class and an implementation of CouchbaseOperations.
Only the CouchbaseTemplate implements CouchbaseOperations. Therefore Reactive integrations will not be able to map other repositories to other entity classes out of the box. I am looking into an alternative in the meantime, by using CouchbaseTemplate and calling the reactive() method on it to get the associated reactive representation. Only other option is for developers to directly access underlying SDK, but even that is not possible, as the opened buckets are defined during app setup phase |
Michael Reiche commented arana3 -
That is correct. That's in the solution provided. Person objects are mapped to the bucket named "protected" and User objects are mapped to the bucket named "mybucket". Be careful not to name your method that returns the template "reactiveCouchbaseTemplate" and also be careful not to name your method that returns the client factory "couchbaseClientFactory" - there are @Override
public void configureReactiveRepositoryOperationsMapping(ReactiveRepositoryOperationsMapping baseMapping) {
try {
ReactiveCouchbaseTemplate personTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("protected"),new MappingCouchbaseConverter());
baseMapping.mapEntity(Person.class, personTemplate); // Person goes in "protected" bucket
ReactiveCouchbaseTemplate userTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter());
baseMapping.mapEntity(User.class, userTemplate); // User goes in "mybucket"
// everything else goes in getBucketName()
} catch (Exception e) {
throw e;
}
} |
Hello @mikereiche one question I need to connect to multiple buckets inside same Cluster but I need to do this dynamically based on data from application.yaml also I don't need to use any Entity objects I want to query using CouchbaseTemplate and operate with json response is this even posible , thanks in advance |
Mapping is by entity type only. |
Well look like no , I figure out a solution and now I operate with multiple buckets without any Entity objects only with JSON string response. |
"I figure out a solution and now I operate with multiple buckets without any Entity objects only with JSON string response" Ok, so what is the issue? |
hey, i implemented mulibucket as explained in this thread, it works. thanks |
Refer to the example - instead of providing a new MappingCouchbaseConverter(), provide your custom couchbase converter. CouchbaseTemplate userTemplate = myCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter()); |
@mikereiche thanks for your reply i have following convertor:
i set this converter inside mapping
But i am getting below exception when save the doc although there is convertor from zonedatetime to couchebasedocument
Can you please help? |
Please create a new issue. @moriyahazan |
please see |
@moriyahazan - I'm not sure if this is your issue, mappingCouchbaseConverter.setCustomConversions(customConversions()); But don't use the same name as the existing @bean method as the spring framework replaces calls to methods with the value of matching @bean methods.
This is why in my examples I always prefix the methods with "my" |
@mikereiche I tried to use special name for converter but issue still persist thanks! |
Please see my response on #1141 |
Just an extra note as Google brought me here when I searched for multi-bucket configuration. These instructions worked perfectly, except the Couchbase auditing support (via @Override
public void configureReactiveRepositoryOperationsMapping(ReactiveRepositoryOperationsMapping baseMapping) {
try {
ReactiveCouchbaseTemplate personTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("protected"),new MappingCouchbaseConverter());
baseMapping.mapEntity(Person.class, personTemplate); // Person goes in "protected" bucket
ReactiveCouchbaseTemplate userTemplate = myReactiveCouchbaseTemplate(myCouchbaseClientFactory("mybucket"),new MappingCouchbaseConverter());
userTemplate.setApplicationContect(applicationContext) // <----- Extra line
baseMapping.mapEntity(User.class, userTemplate); // User goes in "mybucket"
// everything else goes in getBucketName()
} catch (Exception e) {
throw e;
}
} |
Michael Reiche With this connecttion is created to this new cluster but the repository is not getting that connection through CrudRepository. Is there a way to do it ? |
The selection is made on the entity class. You'll need to make another repository interface based on the other entity class. If you still have issues, post the repository classes, the entity classes, the config class and the code that calls the repository methods so I can reproduce it. |
Michael Reiche Couchbase Cluster 1 (This I was able to achieve it by following your comment above) Now I want to have another cluster in the same app. where am facing issue. Here is the link to my code: https://github.com/premvarmak/spring-pvk-data-couchbase/tree/master I have added readme file explaining the setup. But its a very basic setup which I have created following the Spring documentation. |
Michael Reiche I have override CouchbaseTemplate to provide new cluster and bucket information and marked it under new Bean. Than I override configureRepositoryOperationsMapping. And I am able to get two couchbase instances registered but I am not able to attach this new instance configuration with repositories. |
Run with the debugger and set a break-point in the implementation of CouchbaseOperations.resolve(). |
"I am trying to connect to multiple clusters using Spring Data Couchbase." That is completely different than using multiple buckets of the same cluster. Please open a separate issue. |
Yeah!!! I am able to connect to multiple clusters now... Your point "The selection is made on the entity class." Based on this, I created multiple CouchbaseTemplate and mapped respective entities in RepositoryOperationsMapping. And then all is working good... Michael Reiche Thank you for your time :) |
That's great @premvarmak. |
The change is my local. I will commit to the above repository and will let you know here. Thank you... |
Guillaume Durandiere opened DATACOUCH-570 and commented
There is a link about the multibucket configuration in the following documentation (4.0.1) : https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#couchbase.repository.multibucket
But there is nothing about it.
Will you add it soon ?
Affects: 4.0.1 (Neumann SR1)
The text was updated successfully, but these errors were encountered: