1

I'm using a Go API and I need to connect it to my Cassandra DB on a Google Cloud server.

This is my Go connection code:

func SetupDBConnection() {
    cluster := gocql.NewCluster("XX.XXX.XXX.XXX")
    cluster.Keyspace = "afterstr"
    cluster.Consistency = gocql.Quorum

    s, err := cluster.CreateSession()
    if err != nil {
        fmt.Println(err)
    }
}

But, when I run this code, I have this error:

gocql: unable to create session: control: unable to connect to initial hosts: dial tcp xx.xxx.xxx.xxx:9042: i/o timeout

This is my Google Cloud configuration:

server config

server config

server config

I also modified the cassandra.yaml file in my server to change the listen address and the RPC address to put my IP with the port I use to run my Go program that I opened. (It is opened 3 times because I was just testing something)

opened ports

MenyT
  • 1,653
  • 1
  • 8
  • 19
abrd
  • 63
  • 6

1 Answers1

0

Try:

cluster.Authenticator = gocql.PasswordAuthenticator{Username: username, Password: password}
MenyT
  • 1,653
  • 1
  • 8
  • 19
  • I tried to do this but I don't know the user or the password. Do you have any idea what to enter? – abrd Sep 18 '21 at 12:58
  • Try cassandra:cassandra it is default settings and I found this docs. Hope it will help https://cloud.google.com/apigee/docs/hybrid/v1.3/cassandra-tls – MenyT Sep 19 '21 at 19:56