Exception in thread “main” java.lang.RuntimeException: java.util.concurrent.TimeoutException
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:481)
at rx.observables.BlockingObservable.single(BlockingObservable.java:348)
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:612)
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:574)
at com.amadeus.alf.TestCouchBase.createClient(TestCouchBase.java:31)
at com.amadeus.alf.TestCouchBase.main(TestCouchBase.java:15)
Caused by: java.util.concurrent.TimeoutException
at rx.internal.operators.OperatorTimeoutBase$TimeoutSubscriber.onTimeout(OperatorTimeoutBase.java:169)
at rx.internal.operators.OperatorTimeout$1$1.call(OperatorTimeout.java:42)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:43)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Since you don’t write a sentence with a question mark I’m just making some assumptions what you are trying to achieve.
If you want to use N1QL (like you did with the .query()) method, you need to enable it on the environment and also make sure it is running on every node in the cluster manually.
See http://docs.couchbase.com/developer/java-2.0/querying-n1ql.html for more info.
Thanks a lot for your reply. Earlier I wasn’t aware that I have to configure the N1QL server. Now I downloaded the N1QL server on my local and then executed the below command.
“http://localhost:8093” is the url of my query server which I installed locally and configured to look at my couchbase server by running below command from CMD.
My question is I am not able to connect and getting below exception
ARNING: [null][KeyValueEndpoint]: Could not connect to endpoint, retrying with delay 2ms:
java.net.ConnectException: Connection refused: no further information: localhost/127.0.0.1:11210
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208)
at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:287)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:744)
You need to run cbq-engine on every node of the cluster (so if only on localhost, then just on localhost is fine).
That’s wrong: CouchbaseCluster cluster = CouchbaseCluster.create(“http://localhost:8093”);
Just use CouchbaseCluster.create(“localhost”); because it will try to find the query engine on 8093 out of the box.
Not sure if this query is going to work. Try something like “SELECT * FROM devalf”
One note: in the future, once N1QL is packaged into the server you dont even need to run cbq-engine manually or use queryEnabled. You just create the cluster, open the bucket and you’re good to go.
Thanks a lot for your quick reply.
Currently I installed Couchbase community server 2.2.0 version in my local system and then ran the cbq-engine in my local system.
Also getting the above mentioned TimeOut Exception.
Is this exception related to queryEnabled=false ? if yes then what I need to do to solve the issue.
Thanks for your help. Now I am able to connect and query the bucket.
I have one more query.
Previously I used to use CouchbaseClient API to save any data to the Couchbase server by add(key,json).
Can you please send me the piece of code through which I can save and update json to the Couchbase by using CouchbaseCluster API
And then you can decide what type of document to store. The easiest is the JsonDocument, which allows you to store JSON through a JsonObject, but if you already have your own JSON handling in place you can use the RawJsonDocument to read and write raw JSON data.
You do not need to pass in all nodes of the cluster, just a few seed nodes so that the client is able to establish initial contact.
So if you have a 5 node cluster, I recommend passing in any 3 that you see fit. Remember it will be removed anyways and the full one is taken, it’s really just for initial contact.
If in my cluster 5 nodes are there and I am just using 3 nodes for getting connection, in that case the data I have saved will be stored in all the 5 nodes or will be stored in 3 nodes which I had given for connection.
Okay, maybe let me rephrase it so that it gets clearer:
The list you pass in when you call CouchbaseCluster.create(…); is just to make an initial contact with the cluster. Once we have an initial contact, your list (regardless of what you passed in) will be thrown away and a fresh config list from the cluster will be used.
So even if you have a 50 node cluster and you only pass in 2 nodes here, all will be fine. You can also pass in only one and that will work too, but if this node happens to be down at the time of connect your application server will not be able to establish the contact. This is why we recommend in to pass in 2-3 nodes to the list so if one is down it can try the next.
Hi,
Seems like .queryEnabled(true) is not longer necessary in Couchbase server >=4.5
I cannot find the method in the DefaultCouchbaseEnvironment Class for the new java smart client?
Am I right? (I have the timeout issue as well).
Cheers,
Ivan
Yes queryEnabled was deprecated and taken away in SDK version 2.3.0. This is not related to the server version, as long as you have query service setup, it should work. Can you elaborate more on the timeout, does the query always times out and which client version are you using?
Sorry. It was our fault. A sysadmin was redirecting a port to the wrong place. Kind of happens when the developer cannot see directly the deployment environment.
Thanks anyways,
I <3 couchbase cause the forums are very active. KUDOS.
Could you please elaborate what was wrong configuration made by sysadmin?.. Cause I’m facing timeout on basic select query (select * from bucket use keys ‘key’). Strange thing is query times out after around 10 k iterations and all the subsequent query iterations fail. I’m using java client 2.2.8. We have 5 nodes in the cluster with two nodes running query and index service.
@thenamespraveen I wish I knew exactly. He would not tell exactly cause they messed up, but they did tell me it was a port redirection issue. I am using java client 2.4.4
Mine is a development environment, only one node. All services running in the same node (they wont give me more nodes, cause they don’t understand horizontally scaling).
I wish I could help you more.