Cassandra соединение не удается

1

Ошибка

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /172.17.1.XX:9160 (com.datastax.driver.core.TransportException: [/172.17.1.XX:9160] Cannot connect))
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:80)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1145)
    at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:313)
    at com.example.cassandra.Client.connect(Client.java:18)
    at com.example.cassandra.Client.main(Client.java:74)

Версия datastax - dse 4.5.2

Линией, где возникает ошибка, является connect(node)

   cluster = Cluster.builder().addContactPoint(node).withPort(9160).build();
   Metadata metadata = cluster.getMetadata(); //Error at this line

Вызов функции

     public static void main(String a[])
     {
       System.out.println("I am in");
       Client client = new Client();
       client.connect("172.17.1.XX");
       client.close();
     }

pom.xml -

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.cassandra</groupId>
<artifactId>simple-client</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>

<dependencies>
  <dependency>
   <groupId>com.datastax.cassandra</groupId>
   <artifactId>cassandra-driver-core</artifactId>
   <version>2.1.0</version>
  </dependency>
<dependency>
  <groupId>org.apache-extras.cassandra-jdbc</groupId>
  <artifactId>cassandra-jdbc</artifactId>
  <version>1.2.5</version>
  </dependency>
</dependencies>

<build>
   <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.3.2</version>
      <configuration>
        <mainClass>com.example.cassandra.Client</mainClass>
      </configuration>
    </plugin>
     <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
     </plugins>
   </build>
  </project>

Я добавил эту ссылку

Тогда я попробовал

 telnet 172.17.1.XX 9160

 Trying 172.17.1.XX...
 Connected to 172.17.1.XX.
 Escape character is '^]'.

Если я что-то напечатаю, он говорит, что connection closed by foreign agent

 netstat -plten 

по 172.17.1.XX

shows 

 tcp        0      0 127.0.0.1:8984          0.0.0.0:*               LISTEN      0          73148094    19145/java
 tcp        0      0 127.0.0.1:7000          0.0.0.0:*               LISTEN      0          73148635    19145/java
 tcp        0      0 0.0.0.0:7199            0.0.0.0:*               LISTEN      0          73148631    19145/java
 tcp        0      0 0.0.0.0:50370           0.0.0.0:*               LISTEN      0          73148632    19145/java
 tcp        0      0 0.0.0.0:9160            0.0.0.0:*               LISTEN      0          73148104    19145/java
 tcp        0      0 0.0.0.0:33935           0.0.0.0:*               LISTEN      0          73148630    19145/java
 tcp        0      0 0.0.0.0:9042            0.0.0.0:*               LISTEN      0          73148103    19145/java
 tcp        0      0 0.0.0.0:8983            0.0.0.0:*               LISTEN      0          73148083    19145/java

Итак, как я могу решить эту проблему? Любые решения?

Теги:
maven
cassandra
telnet

1 ответ

2
Лучший ответ

Вы подключаетесь к неправильному порту: Java Driver подключается к Native Port (обычно 9042), а не к Thrift Port (обычно 9160). Изменить эту строку

cluster = Cluster.builder().addContactPoint(node).withPort(9042).build();
  • 0
    Так что, если мне нужно использовать в Docker-контейнере, мне нужно выставить этот порт? Где я могу изменить этот порт?
  • 1
    Да, вы должны выставить этот порт. Это настраивается в файле cassandra.yaml.
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню