【发布时间】:2021-11-10 17:00:51
【问题描述】:
我目前正在开发一个带有 Go api 的项目。它与 Google Cloud 服务器上的 Cassandra 进行通信。
问题是当我尝试向 Cassandra 发出请求时,Go 返回了几个错误。经过多次测试,我认为问题出在 Go 和 Cassandra 之间的连接不起作用。
是否有安全检查来建立连接?还是我只是在代码中犯了一个错误?
我使用gocql 连接到 Cassandra。这是 Go 连接脚本和调用 Cassandra 的请求。
type DBConnection struct {
cluster *gocql.ClusterConfig
session *gocql.Session
}
var connection DBConnection
func SetupDBConnection() {
connection.cluster = gocql.NewCluster(google cloud server adress)
connection.cluster.Consistency = gocql.Quorum
connection.cluster.Keyspace = "keyspace name"
connection.session, _ = connection.cluster.CreateSession()
}
func ExecuteQuery(query string, values ...interface{}) {
connection.session.Query(query).Bind(values...).Exec()
}
go cql 重新运行此错误:
gocql : 不可能的 de créer la session : 控制 : 不可能的 de se 连接器 aux hôtes initiaux : composez tcp xx.xxx.xxx.xxx:9042 : délai d'attente d'e/s
【问题讨论】:
-
Cassandra 在 Compute Engine 虚拟机上运行,是吗?应用程序是否在 GCP 之外运行?如果是这样,您是否更改了 VM 的防火墙规则以打开 Cassandra 需要的端口?
-
是的,cassandra 与 go 在不同的机器上,但是如何知道 cassandra 需要哪个端口? @GabeWeiss
标签: go google-cloud-platform cassandra