Java Riak 连接问题

标签 java linux eclipse connection riak

尝试将我的 Java Eclipse 连接到 Linux Ubuntu 上的 Riak 服务器。 遵循了一些指南,但仍然不起作用。 使用: - Riak-客户端-2.0.2 - Eclipse Oxygen.1a 版本 (4.7.1a) - Ubuntu 16.04.3 - openjdk版本“1.8.0_151”

之前使用 slf4j 遇到过一些问题,所以我添加了一个外部 jar: slf4j-jdk14-1.7.25-sources 来解决它。

我的代码:

import com.basho.riak.client.api.RiakClient;
import com.basho.riak.client.api.commands.kv.FetchValue;
import com.basho.riak.client.api.commands.kv.StoreValue;
import com.basho.riak.client.core.query.Location;
import com.basho.riak.client.core.query.Namespace;


import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;

public class ProdukteEinlesen {
    public static void main(String [] args) throws UnknownHostException, ExecutionException, InterruptedException {

        RiakClient client = RiakClient.newClient(8098, "127.0.0.1");
        Location location = new Location(new Namespace("TestBucket"),"TestKey");

        FetchValue fv = new FetchValue.Builder(location).build();
        FetchValue.Response response = client.execute(fv);

        // Fetch object as String
        String value = response.getValue(String.class);
        System.out.println(value);

        client.shutdown();
    }
}

现在我得到了这个:

 Dez 04, 2017 5:58:23 PM com.basho.riak.client.core.RiakNode start
INFORMATION: RiakNode started; 127.0.0.1:8098
Dez 04, 2017 5:58:23 PM com.basho.riak.client.core.RiakCluster start
INFORMATION: RiakCluster is starting.
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:-2083854054 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:674162571 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:1161062152 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:-1411904647 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:-1369356068 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:957736106 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:-1598195494 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:-1723639977 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$2 operationComplete
SCHWERWIEGEND: inAvailable channel closed; id:-1232050671 127.0.0.1:8098
Dez 04, 2017 6:03:20 PM com.basho.riak.client.core.RiakNode$3 operationComplete
SCHWERWIEGEND: Channel closed while operation in progress; id:-459317961 127.0.0.1:8098
Dez 04, 2017 6:08:17 PM com.basho.riak.client.core.RiakNode healthCheckFailed
SCHWERWIEGEND: RiakNode failed healthcheck operation; health checking; 127.0.0.1:8098 java.io.IOException: Channel closed while performing health check op.
Dez 04, 2017 6:08:17 PM com.basho.riak.client.core.DefaultNodeManager nodeStateChanged
INFORMATION: NodeManager moved node to unhealthy list; 127.0.0.1:8098
Dez 04, 2017 6:08:17 PM com.basho.riak.client.core.RiakNode$3 operationComplete
SCHWERWIEGEND: Channel closed while operation in progress; id:-1254319488 127.0.0.1:8098
Exception in thread "main" java.util.concurrent.ExecutionException: com.basho.riak.client.core.NoNodesAvailableException
    at com.basho.riak.client.core.FutureOperation.get(FutureOperation.java:260)
    at com.basho.riak.client.api.commands.CoreFutureAdapter.get(CoreFutureAdapter.java:52)
    at com.basho.riak.client.api.RiakCommand.execute(RiakCommand.java:89)
    at com.basho.riak.client.api.RiakClient.execute(RiakClient.java:293)
    at ProdukteEinlesen.main(ProdukteEinlesen.java:18)
Caused by: com.basho.riak.client.core.NoNodesAvailableException
    at com.basho.riak.client.core.RiakCluster.retryOperation(RiakCluster.java:468)
    at com.basho.riak.client.core.RiakCluster.access$1000(RiakCluster.java:47)
    at com.basho.riak.client.core.RiakCluster$RetryTask.run(RiakCluster.java:553)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

我的 Riak DB 已经通过命令运行良好。

最佳答案

您似乎使用了不正确的 Riak 连接端口号。 Protocol Buffers API 的正确端口是 8087(假设您没有更改默认值)。端口 8098 用于 HTTP,您必须使用 cURL 或其他 HTTP 客户端测试服务器。 Java 代码应如下所示:

RiakClient client = RiakClient.newClient(8087, "127.0.0.1");

关于Java Riak 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50844078/

相关文章:

java - 当调试器完成应用程序时,如何使 Eclipse 自动跳回开发视角?

python - Debian 没有名为 numpy 的模块

linux - 使用linux命令随机选择列

java - 主类中的变量

java - 使用 StandardCharset UTF-8 处理格式错误的异常

java - 具有覆盖 equals 和 hashCode 的 HashMap 不起作用

c - sk_buff 函数 skb_network_header() 和 skb_mac_header() 有什么作用?

eclipse - 在 Eclipse 工作区中搜索字符串

java - GWT 项目中的 tomcat-maven-plugin。 : org. codehaus.mojo 和 org.apache.tomcat.maven 插件有什么区别

java - 将库复制到网络存档中