Configure the client
Set a client's addresses, credentials, TLS, retry budget, and batch bounds.
You configure a client once, when you create it, and share it across your program. This page lists every option. Install and connect shows where to point a client, and Handle errors what it retries for you. Over HTTP, curl has the same settings for a single request.
Client options
A client needs an address, and every other option has a default. Here a client has a fallback address, a shorter connection timeout, and a shorter retry budget:
c, err := client.New(client.Options{
// The second address is a fallback for when a connection fails.
Addrs: []string{"localhost:7781", "localhost:7782"},
DialTimeout: 2 * time.Second, // for one connection attempt
RetryBudget: 10 * time.Second, // for retrying passing failures
})
if err != nil {
return err
}
defer c.Close()Set exactly one address form; a client refuses two. When you set none, the client reads NOVA_DOMAIN, and NOVA_ADDR only when NOVA_DOMAIN is unset. It reads NOVA_LOCATION whenever you set no location. NOVA_ADDR holds either one HTTP URL or a comma-separated list of gRPC addresses. The TypeScript SDK reads the environment only where process.env exists.
You can also set Location / location beside any address, without a domain. The client then sends that location with every bucket it creates or updates, and a bucket in another location is refused. In TypeScript, the HTTP transport also takes a fetch function, and the gRPC transport a sealFollowMs: how long an append waits for a split range's successors to be known, 5 seconds by default.
Authenticate
A credential goes with every call. Here the client sends a token you already have:
// With no address set, the client reads NOVA_ADDR.
c, err := client.New(client.Options{
Auth: client.Bearer(os.Getenv("NOVA_TOKEN")),
})
if err != nil {
return err
}
defer c.Close()
tail, err := c.CheckTail(ctx, client.Address{Bucket: "demo", Key: "events"})
if err != nil {
return err
}
fmt.Println("the next record gets", tail.SeqNum)the next record gets 0With an api key, the SDK asks for one token per stream it calls, and one per bucket for bucket calls. Each token carries every grant the key has there. A bucket listing asks for the grant to list the buckets its prefix covers, and an admin call for nova:admin. The SDK keeps up to 64 tokens and asks for a new one 30 seconds before a token expires.
To share one token across every call, give the credential a Scope / scope: a set of grants in the form API keys and tokens describes. To get tokens from a service other than the one the client connects to, such as your own token service, give the credential an ExchangeURL / exchangeUrl. The SDK then exchanges the key there. A malformed key fails when you create the client, before anything is sent.
Connect over TLS
To verify the server, give the client the certificate of the authority that signed it. Here the address comes from NOVA_ADDR:
// The certificate of the authority that signed the node's.
tlsConfig, err := client.ServerTLS("ca.pem")
if err != nil {
return err
}
// The address comes from NOVA_ADDR.
c, err := client.New(client.Options{TLS: tlsConfig})
if err != nil {
return err
}
defer c.Close()
tail, err := c.CheckTail(ctx, client.Address{Bucket: "demo", Key: "events"})
if err != nil {
return err
}
fmt.Println("the next record gets", tail.SeqNum)the next record gets 0client.ServerTLS("") uses the system's trusted certificates. For a server that also checks the client, client.MutualTLS(certFile, keyFile, caFile) presents your certificate.
A client with a TLS setting refuses an http:// address, since the two contradict each other.
Client limits
Every client bounds what it holds. Both SDKs use the same values, and none of them is an option:
| Limit | Value | At the limit |
|---|---|---|
| Redirects followed in one call | 3 | The client returns the last answer |
| Remembered stream leaders | 4,096 | The oldest is forgotten, which costs one more redirect later |
| Connections | 128 | The least recently used idle connection closes. A new one is refused only while all 128 carry calls |
| Calls on one connection | 1,000 | The client opens another connection to that node, up to 64 |
| A producer's open attempt | 5 s | The client tries the next address, within the retry budget |
| Cached tokens | 64 | The oldest is forgotten, and asked for again when needed |