我一直在尝试使用 gocql 连接到 cosmos cassandra db。
func GetSession(cosmosCassandraContactPoint, cosmosCassandraPort, cosmosCassandraUser, cosmosCassandraPassword string) *gocql.Session {
clusterConfig := gocql.NewCluster(cosmosCassandraContactPoint)
port, err := strconv.Atoi(cosmosCassandraPort)
if err != nil {
log.Fatal(err)
}
clusterConfig.Port = port
clusterConfig.ProtoVersion = 4
clusterConfig.Authenticator = gocql.PasswordAuthenticator{Username: cosmosCassandraUser, Password: cosmosCassandraPassword}
clusterConfig.SslOpts = &gocql.SslOptions{Config: &tls.Config{MinVersion: tls.VersionTLS12}}
clusterConfig.ConnectTimeout = 10 * time.Second
clusterConfig.Timeout = 10 * time.Second
clusterConfig.DisableInitialHostLookup = true
// uncomment if you want to track time taken for individual queries
//clusterConfig.QueryObserver = timer{}
// uncomment if you want to track time taken for each connection to Cassandra
//clusterConfig.ConnectObserver = timer{}
session, err := clusterConfig.CreateSession()
if err != nil {
log.Fatal("Failed to connect to Azure Cosmos DB", err)
}
return session
}
我收到以下错误:
unable to create session: control: unable to connect to initial hosts: Invalid Cosmos DB account or key
不确定这里的问题是什么。