2

我尝试在亚马逊实例上安装和运行 Apache Cassandra。在实例上一切正常。我也可以通过 cassandra-cli --host PUBLIC_IP --port 9160 从远程机器连接。

但是当我尝试通过 spring-data-cassandra (1.2.0.Build snapshot) 连接时,cassandra 抛出错误:

All host(s) tried for query failed (tried: /PUBLIC_IP:9160  (com.datastax.driver.core.ConnectionException: [/PUBLIC_IP:9160] Unexpected error during transport initialization (com.datastax.driver.core.TransportException: [/PUBLIC_IP:9160] Channel has been closed)))

我的 cassandra.yuml:

listen_address: localhost
start_native_transport: true
native_transport_port: 9042
start_rpc: true
rpc_address: 0.0.0.0
rpc_port: 9160
broadcast_rpc_address: PRIVATE_AWS_INSTANCE_IP

cassandra-cli --host PUBLIC_IP --port 9160 工作正常。

簇豆:

@Bean
public CassandraClusterFactoryBean cluster() throws Exception {

    CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
    cluster.setContactPoints(env.getProperty("cassandra.contactpoints"));
    cluster.setPort(Integer.parseInt(env.getProperty("cassandra.port")));  
    return cluster;
}

道具:

cassandra.contactpoints=PUBLIC_IP
cassandra.port=9160
cassandra.keyspace=mykeyspace

依赖项:

<properties>
    <spring.version>4.1.0.RELEASE</spring.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-cql</artifactId>
        <version>1.1.0.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

 <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-cassandra</artifactId>
        <version>1.2.0.BUILD-SNAPSHOT</version>
    </dependency>

UPD

通过将端口更改为 9042(本机)解决了问题

4

1 回答 1

4

您正在使用本机驱动程序,但连接到 Thrift 端口。试试 9042。

于 2014-09-19T20:40:46.713 回答