连接到 Cassandra 时出现“gocql:超时内没有响应连接启动”

Abh*_*hek 1 go cassandra gocql

尝试使用 gocql(Go:1.8.3)连接到 Cassandra(v 3.10.0)。这是错误

gocql:无法拨号控制 conn [hostIP]:gocql:超时内对连接启动没有响应

恐慌:gocql:无法创建会话:控制:无法连接到初始主机:gocql:超时内没有响应连接启动

这是代码...

func test() {
    cluster := gocql.NewCluster("hostIP")
    cluster.ProtoVersion = 4
    cluster.Authenticator = gocql.PasswordAuthenticator{
        Username: "<username>",
        Password: "<password>",
    }
    cluster.Keyspace = "myspace"
    cluster.Consistency = gocql.One
    session, err := cluster.CreateSession()
    if err != nil {
        panic(err)
    }
    defer session.Close()
}
Run Code Online (Sandbox Code Playgroud)

谁能指出我可能遗漏了什么?

Abh*_*hek 8

好的..这已经解决了。发布以防这最终帮助某人

第一个错误是通过使用ConnectTimeoutie解决的cluster.ConnectTimeout = time.Second * 10

然后我得到了这个错误(发现使用gocql_debug)- unable to dial "<internal VM IP>": dial tcp <internal VM IP>:9042: i/o timeout(更多在这里

我通过设置cluster.DisableInitialHostLookup为 true解决了它