问题描述
我目前正在探索如何在使用 spring-data-couchbase 的同时主动初始化两个集群,目标是连接到两个集群并自动连接两个存储桶,使用一个作为主要的,第二个作为辅助的,这是使用备用存储桶,以防主集群出现故障。
通常,单个集群和存储桶的设置相当简单:
@Configuration
@Data
@Slf4j
public class CouchbaseConfigurationPrimary extends AbstractCouchbaseConfiguration {
private String bucketName;
private String username;
private String password;
private String timeout;
private String ip;
public CouchbaseConfigurationPrimary(@Value("${couchbase.cluster.bucketname}") String bucketName,@Value("${couchbase.cluster.user}") String username,@Value("${couchbase.cluster.password}") String password,@Value("${couchbase.cluster.ip}") String ip,@Value("${couchbase.cluster.timeout}") String timeout){
this.bucketName = bucketName;
this.username = username;
this.password = password;
this.timeout = timeout;
this.ip = ip;
}
@Override
protected List<String> getBootstrapHosts() {
return Arrays.asList(ip);
}
@Override
protected String getBucketName() {
return this.bucketName;
}
@Override
protected String getBucketPassword() {
return this.password;
}
protected CouchbaseEnvironment getEnvironment(){
Long timeOut = Long.valueOf(timeout);
return DefaultCouchbaseEnvironment
.builder()
.keepAliveTimeout(timeOut)
.queryTimeout(timeOut)
.connectTimeout(timeOut)
.build();
}
}
然后可以在整个服务中自动装配存储桶:
@Autowired
public Bucket couchbaseBucket
谁能解释一下如何使用 spring-data-couchbase 3.1.5 创建两个不同的集群?
目标是能够连接到两个不同的集群并使用不同的限定名称初始化两个存储桶以自动装配它们,如下所示:
...
@Autowired
@Qualifier("couchbaseBucketPrimary")
public Bucket couchbaseBucketPrimary
@Autowired
@Qualifier("couchbaseBucketSecondary")
public Bucket couchbaseBucketSecondary
...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)