is there a way to connect to bitnami using gocql in a docker compose multi-container application?

Cassandra takes a few seconds to startup and begin accepting connections; backend is attempting to connect before it is ready. Your configuration works OK (for me) if you start up backend after a small delay (using docker-compose start backend). Modifying backend to retry the connection works reliably for me i.e.

for {
    _, err := cluster.CreateSession()
    if  err == nil {
        break
    }
    log.Printf("CreateSession: %v", err)
    time.Sleep(time.Second)
}
log.Printf("Connected OK")

Logs:

backend_1    | 2020/11/04 17:53:23 CreateSession: gocql: unable to create session: unable to discover protocol version: dial tcp 172.26.0.2:9042: connect: connection refused
backend_1    | 2020/11/04 17:53:24 CreateSession: gocql: unable to create session: unable to discover protocol version: dial tcp 172.26.0.2:9042: connect: connection refused
.......
backend_1    | 2020/11/04 17:53:36 CreateSession: gocql: unable to create session: unable to discover protocol version: dial tcp 172.26.0.2:9042: connect: connection refused
backend_1    | 2020/11/04 17:53:37 Connected OK

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top