I have provisioned a Cosmos DB (Cassandra API) instance on Azure.
I'm able to connect to it through cqlsh. But, getting different errors when trying to connect to it through gocql.
The following code generates this error:
gocql: unable to dial control conn 40.112.241.29: read tcp 192.168.0.106:58864->40.112.241.29:10350: read: connection reset by peer
Here's the code snippet:
cluster := gocql.NewCluster("<host here>")
cluster.Port = 10350
cluster.Timeout = 10000
cluster.SocketKeepalive = 60 * time.Second
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: 3}
cluster.Consistency = gocql.LocalOne
cluster.ProtoVersion = 1
cluster.ReconnectionPolicy = &gocql.ConstantReconnectionPolicy{MaxRetries: 10, Interval: 8 * time.Second}
cluster.Keyspace = "<keyspace here>"
cluster.DisableInitialHostLookup = true
cluster.IgnorePeerAddr = true
cluster.Authenticator = gocql.PasswordAuthenticator{Username: "<username here>", Password: "<password here>"}
_, err := cluster.CreateSession()
if err != nil{
// handle the error
}
Just to add to this, gocql is listed as an officially supported driver under this page:
https://docs.microsoft.com/en-us/azure/cosmos-db/cassandra-support#cassandra-driver