I'm trying to create a Spring Batch in order to copy Couchbase data from one cluster to another. I'm using Spring Data Couchbase.
But I can't figure out how to have 2 different repositories on 2 different clusters.
I've found many examples on how to have multiple buckets on the same cluster based on OperationsMapping but it does'nt meet my needs because in my case the Data Model is the same.
When I use the second repository (the target where the bucket is empty) to test if the document from the source repository exists, I get true. So it seems the test is made in the same repository (the source).
I tried to declare custom beans with custom names for CouchbaseTemplate, CouchbaseClientFactory, CouchbaseClusterEnvironment and CouchbaseCluster with no luck.
Thanks for help !
Here is the example of one of my 2 configuration classes (the second is the same with 'source' replaced by 'target') :
@Configuration
@EnableCouchbaseRepositories(repositoryBaseClass = SourceDocumentRepository.class, couchbaseTemplateRef = "sourceCouchbaseTemplate")
public class SourceCouchbaseConfiguration extends AbstractCouchbaseConfiguration {
... getters overriden : connectionString, user, pwd, bucket, scope
@Bean(name = "sourceCouchbaseCluster", destroyMethod = "disconnect")
public Cluster sourceCouchbaseCluster(ClusterEnvironment sourceCouchbaseClusterEnvironment) {
return Cluster.connect(getConnectionString(), ClusterOptions.clusterOptions(authenticator()).environment(sourceCouchbaseClusterEnvironment));
}
@Bean(name = "sourceCouchbaseClusterEnvironment", destroyMethod = "shutdown")
public ClusterEnvironment sourceCouchbaseClusterEnvironment() {
ClusterEnvironment.Builder builder = ClusterEnvironment.builder();
builder.jsonSerializer(JacksonJsonSerializer.create(couchbaseObjectMapper()));
configureEnvironment(builder);
return builder.build();
}
@Bean("sourceCouchbaseClientFactory")
public CouchbaseClientFactory sourceCouchbaseClientFactory() {
return new SimpleCouchbaseClientFactory(getConnectionString(), authenticator(), getBucketName(), getScopeName());
}
@Bean("sourceCouchbaseTemplate")
public CouchbaseTemplate sourceCouchbaseTemplate() {
return new CouchbaseTemplate(sourceCouchbaseClientFactory(), new MappingCouchbaseConverter());
}
@Bean("sourceReactiveCouchbaseTemplate")
public ReactiveCouchbaseTemplate sourceReactiveCouchbaseTemplate() {
return new ReactiveCouchbaseTemplate(sourceCouchbaseClientFactory(), new MappingCouchbaseConverter());
}
@Bean("sourceCouchbaseRepositoryOperationsMapping")
public RepositoryOperationsMapping sourceCouchbaseRepositoryOperationsMapping(CouchbaseTemplate sourceCouchbaseTemplate) {
return new RepositoryOperationsMapping(sourceCouchbaseTemplate);
}
}
I ended up creating one repository for my source based on
AbstractCouchbaseConfigurationwith my custom findBy with pagination.And for the target, I created a simple configuration class with custom names for the beans :
This way, I can use my
sourceRepositoryand mytargetCouchbaseTemplatein my app :