Simple Example with JAVA, Couchbase and EC2 (AWS)

#1

Hello!! I’m trying to connect a java application to couchbase.
With the following code, I could get the bucket name without problem

CouchbaseCluster cluster=CouchbaseCluster.create("qa.....com");
ClusterManager cManager = cluster.clusterManager("Administrator", "...");
BucketSettings b = cManager.getBucket("vdb");
System.out.println(b.name());

However, when I executed the following code to create a bucket I had a timeout problem:

CouchbaseCluster cluster=CouchbaseCluster.create("qa.....com");
ClusterManager cManager = cluster.clusterManager("Administrator", "...");
Bucket b = cluster.openBucket("vdb");
System.out.println(b.name());

The error is:

Jan 20, 2015 6:07:14 PM com.couchbase.client.core.CouchbaseCore <init>
INFO: CoreEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=2, computationPoolSize=2, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, packageNameAndVersion=couchbase-java-client/2.0.3 (git: 2.0.3)}
Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.TimeoutException
	at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:93)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:108)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:99)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:89)
	at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:79)
	at Main.main(Main.java:14)
Caused by: java.util.concurrent.TimeoutException
	... 6 more

What should I do??
Thanks!

#2

I never used ClusterManager to open bucket, but have been only using CouchbaseCluster to open bucket, and haven’t had timeout issue so far. Maybe you can change to CouchbaseCluster?

#3

Hi, thanks for your awswer.

I used CouchbaseCluster to open the bucket, but was not work.

CouchbaseCluster cluster=CouchbaseCluster.create("ip");
Bucket b = cluster.openBucket("vdb");
System.out.println(b.name());

How can i define the password to access to the bucket?

Could you give me an example of your code?

Thanks,
Carlos

#4

There’s a version of CouchbaseCluster.openBucket() that takes in name and password. But I haven’t used it so far, and I’m new to Couchbase also.

http://docs.couchbase.com/sdk-api/couchbase-java-client-2.0.3/

#5

@cfontana0 But after I stopped on your code longer, I realized that I have never had issue to open bucket even I do have name and password set for my nodes :laughing:

#6

There’s an example in the documentation @cfontana0.

#7

Hi @ingenthr, thanks for your reply.

I used the example that you indicated me… but I have the same problem.

If I run the following code:

CouchbaseCluster cluster=CouchbaseCluster.create("qa.....com");
ClusterManager cManager = cluster.clusterManager("Administrator", "...");
BucketSettings b = cManager.getBucket("vdb");

I have the following results:

INFO: CoreEnvironment: {sslEnabled=false, sslKeystoreFile=‘null’, sslKeystorePassword=‘null’, queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=2, computationPoolSize=2, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, packageNameAndVersion=couchbase-java-client/2.0.3 (git: 2.0.3)}
Jan 21, 2015 10:55:22 AM com.couchbase.client.core.node.CouchbaseNode$5 call
INFO: Connected to Node qa…com

But if I run the following code:

Cluster cluster = CouchbaseCluster.create(“qa.vmobiletech.com”);
Bucket bucket = cluster.openBucket(“vdb”, “vmobile”);

I have the following results:

INFO: CoreEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=2, computationPoolSize=2, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, packageNameAndVersion=couchbase-java-client/2.0.3 (git: 2.0.3)}
Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.TimeoutException

I think that the problem is not in the server, because I could connect with the 1st option…

Thanks,
Carlos

#8

Hi! I found the problem.
It was related to the AWS server. The port 11210 was blocked… I modified it and the application works.

Thanks!