cassandra在java中读取超时,但在cqlsh上运行良好

p5fdfcr1  于 2021-06-14  发布在  Cassandra
关注(0)|答案(0)|浏览(308)

我正在java中对cassandra运行一个select查询。它返回读取超时异常。问题是在cqlsh中没有产生错误。所以问题出在我猜的代码中。我正在使用flink连接到cassandra。而且我认为可能问题出在cqlsh中,我需要按enter键以获取更多结果。也许这就是停止查询的原因驱动器读取所有结果。当我使用limit 100时,它运行良好。我更改了cassandra.yaml读取配置,但没有任何更改。

ClusterBuilder cb = new ClusterBuilder() {
            @Override
            public Cluster buildCluster(Cluster.Builder builder) {
                return builder.withPort(9042).addContactPoint("127.0.0.1")
                        .withSocketOptions(new SocketOptions().setReadTimeoutMillis(60000).setKeepAlive(true).setReuseAddress(true))
                         .withLoadBalancingPolicy(new RoundRobinPolicy())
                        .withReconnectionPolicy(new ConstantReconnectionPolicy(500L))
                        .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
                        .build();
            }
        };

        CassandraInputFormat<Tuple1<ProfileAlternative>> cassandraInputFormat = new CassandraInputFormat("SELECT toJson(profilealternative) FROM profiles.profile where skills contains 'Financial Sector'  ", cb);

        cassandraInputFormat.configure(null);
        cassandraInputFormat.open(null);

        Tuple1<ProfileAlternative> testOutputTuple = new Tuple1();

        while (!cassandraInputFormat.reachedEnd()) {
            cassandraInputFormat.nextRecord(testOutputTuple);
            System.out.println(testOutputTuple.f0);
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题