java

时间:2018-01-16 07:07:13

标签: java cassandra datastax cassandra-3.0

我正在使用DataStax驱动程序连接到Cassandra节点。下面是连接器的代码。

public void connect(String node, Integer port, String username, String password) throws Exception {
        try {
            Builder b = Cluster.builder().addContactPoint(node).withCredentials(username.trim(), password.trim());
            if (port != null) {
                b.withPort(port);
            }
            cluster = b.build();

            session = cluster.connect();
        } catch (Exception e) {
            throw new Exception("can not connect to the node :"+e.getMessage());
        }
    }

我在Cassandra.yaml文件中设置了身份验证器

  

authenticator:PasswordAuthenticator

在调用connect方法时,显示以下错误:

  

主机localhost / 127.0.0.1上的身份验证错误:9042:主机   localhost / 127.0.0.1:9042需要身份验证,但不需要身份验证器   在群集配置中找到

cqlsh shell能够使用Cassandra的相同配置连接到节点。谁能说出我在这里失踪了什么?

编辑: 异常堆栈 在

  

com.datastax.driver.core.AuthProvider $ 1.newAuthenticator(AuthProvider.java:40)     在com.datastax.driver.core.Connection $ 5.apply(Connection.java:259)     在com.datastax.driver.core.Connection $ 5.apply(Connection.java:244)     在   com.google.common.util.concurrent.AbstractTransformFuture $ AsyncTransformFuture.doTransform(AbstractTransformFuture.java:211)     在   com.google.common.util.concurrent.AbstractTransformFuture $ AsyncTransformFuture.doTransform(AbstractTransformFuture.java:200)     在   com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:130)     在   com.google.common.util.concurrent.MoreExecutors $ DirectExecutor.execute(MoreExecutors.java:399)     在   com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:902)     在   com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:813)     在   com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:655)     在   com.datastax.driver.core.Connection $ Future.onSet(Connection.java:1302)     在   com.datastax.driver.core.Connection $ Dispatcher.channelRead0(Connection.java:1083)     在   com.datastax.driver.core.Connection $ Dispatcher.channelRead0(Connection.java:1006)     在   io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在   io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)     在   io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在   io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)     在   io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在   io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)     在   io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)     在   io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在   io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)     在   io.netty.channel.DefaultChannelPipeline $ HeadContext.channelRead(DefaultChannelPipeline.java:1359)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)     在   io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)     在   io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935)     在   io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:141)     在   io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)     在   io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)     在   io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)     在io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)at   io.netty.util.concurrent.SingleThreadEventExecutor $ 5.run(SingleThreadEventExecutor.java:886)     在   io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)     在java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

解决了:

错误是由于某些后台线程试图在没有身份验证的情况下连接到服务器,这些在以前的调试会话中未被终止!