我正在尝试从 Riak 执行一个简单的数据获取作为字符串。
我们正在尝试执行示例代码,但我们收到了错误。这是为从 Riak 获取数据而编写的 Java 代码
我确保 riak 由Sudo Riak Start运行
错误如下:
Exception in thread "main" com.basho.riak.client.RiakRetryFailedException: java.io.EOFException
at com.basho.riak.client.cap.DefaultRetrier.attempt(DefaultRetrier.java:79)
at com.basho.riak.client.cap.DefaultRetrier.attempt(DefaultRetrier.java:81)
at com.basho.riak.client.cap.DefaultRetrier.attempt(DefaultRetrier.java:81)
at com.basho.riak.client.cap.DefaultRetrier.attempt(DefaultRetrier.java:81)
at com.basho.riak.client.cap.DefaultRetrier.attempt(DefaultRetrier.java:53)
at com.basho.riak.client.bucket.FetchBucket.execute(FetchBucket.java:72)
at riak.App.main(App.java:15)
Caused by: java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at com.basho.riak.pbc.RiakConnection.receive(RiakConnection.java:110)
at com.basho.riak.pbc.RiakClient.getBucketProperties(RiakClient.java:697)
at com.basho.riak.client.raw.pbc.PBClientAdapter.fetchBucket(PBClientAdapter.java:249)
at com.basho.riak.client.bucket.FetchBucket$1.call(FetchBucket.java:74)
at com.basho.riak.client.bucket.FetchBucket$1.call(FetchBucket.java:1)
at com.basho.riak.client.cap.DefaultRetrier.attempt(DefaultRetrier.java:72)
... 6 more
示例代码:
package riak;
import com.basho.riak.client.IRiakClient;
import com.basho.riak.client.IRiakObject;
import com.basho.riak.client.RiakException;
import com.basho.riak.client.RiakFactory;
import com.basho.riak.client.bucket.Bucket;
public class App
{
public static void main(String[] args) throws RiakException
{
//IRiakClient riakClient = RiakFactory.httpClient();
IRiakClient client = RiakFactory.pbcClient("127.0.0.1", 8098);
Bucket myBucket = client.fetchBucket("TestBucket").execute();
IRiakObject myObject = myBucket.fetch("TestKey").execute();
// note that getValueAsString() will return null here if there's no value in Riak
System.out.println(myObject.getValueAsString());
client.shutdown();
}
}