Hi Team,
Needed your help in opening connection with couchbase one time using Java.
and use every where in my application. Kind of opening connection one time and using every where.
Just similar to datasource connection using for MF DB2.
Appreciate your help if you provide example with Spring Boot.
below is already I have coded in configuration.
Have few questions on below.
1.) Didn’t mentioned anything about connecting cluster below.
Cluster cluster = CouchbaseCluster.create(env,
"localhost"
);
2.) Didn’t mentioned open bucket statement as well.
Bucket secureBucket = cluster.openBucket(“user id”, “psw”);
In which piece of below code above two things will happen.?
Or
Did completely missed above two operations in below code. Please confirm.
@Configuration
@EnableCouchbaseRepositories(basePackages = “org.aexp.springbootcouchbase.mvc”)
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
@Value("#{'${spring.couchbase.bootstrap-hosts}'.split(',')}")
private List<String> couchbasehosts;
@Value("${spring.couchbase.bucket.name}")
private String couchbaseBucketName;
@Value("${spring.couchbase.bucket.password}")
private String couchbaseBucketPassword;
@Value("${spring.couchbase.env.timeouts.connect}")
private Long couchbaseConnectionTimeout;
@Autowired
private CouchbaseEnvironment couchbaseEnvironment;
@Override
protected String getBucketName() {
return couchbaseBucketName;
}
@Override
protected String getBucketPassword() {
return couchbaseBucketPassword;
}
@Override
protected CouchbaseEnvironment getEnvironment() {
CouchbaseEnvironment couchbaseEnvironment = DefaultCouchbaseEnvironment
.builder()
.defaultMetricsLoggingConsumer(true, CouchbaseLogLevel.TRACE, LoggingConsumer.OutputFormat.JSON_PRETTY)
.runtimeMetricsCollectorConfig(DefaultMetricsCollectorConfig.create(30, TimeUnit.SECONDS ))
.networkLatencyMetricsCollectorConfig(DefaultLatencyMetricsCollectorConfig.create(30, TimeUnit.SECONDS ))
.dnsSrvEnabled(false)
.connectTimeout(couchbaseConnectionTimeout)
.build();
return couchbaseEnvironment;
}
@PostConstruct
public void init(){
couchbaseEnvironment.eventBus().get().subscribe(new Action1<CouchbaseEvent>() {
@Override
public void call(CouchbaseEvent event) {
System.out.println(event);
}
}
);
}
@Override
protected List<String> getBootstrapHosts() {
// TODO Auto-generated method stub
return null;
}
}
Regards,
Naganjaneyulu I.