Configure the client

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()
AddrsgRPC addressesDefaultNOVA_ADDR
Nodes to connect to over gRPC. One is enough; the others are fallbacks for when a connection fails
URLHTTP addressDefaultNOVA_ADDR
A node's data bridge or a Gateway, used exactly as given, with any path prefix
Domain, LocationDeploymentDefaultNOVA_DOMAIN, NOVA_LOCATION
A deployment's Gateway. The client also sends the location with every bucket it creates or updates, and a bucket elsewhere is refused
PathStylePath styleDefaultfalse
Sends stream calls to the Gateway's own host, instead of each bucket's host {bucket}.b.{location}.{domain}
DialTimeoutConnection timeoutDefault5 s
The longest one connection attempt takes before the next address is tried
RetryBudgetRetry budgetDefault30 s
How long the client retries a call that failed for a passing reason, before it gives up
TLSTLSDefaultPlaintext
Verifies the server, and can present a client certificate; see below
AuthCredentialDefaultNOVA_API_KEY, or none
The credential sent with every call; see below
MaxBatchBytes, MaxBatchRecordsBatch boundDefault1 MiB, 1,000
The bound a one-shot append is checked against before a node has told the client its own. Producers always use the node's

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)
Output
the next record gets 0
APIKeyApi key
Exchanges the key for short-lived tokens, and renews them on its own. Use it by default
BearerToken
Sends a token you got elsewhere, such as from your own sign-in service
BearerFuncToken function
Calls your function for the token before each call, so you can renew it
BasicAuthLogin
A username and password, for an operator's admin calls

With 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)
Output
the next record gets 0

client.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:

LimitValueAt the limit
Redirects followed in one call3The client returns the last answer
Remembered stream leaders4,096The oldest is forgotten, which costs one more redirect later
Connections128The least recently used idle connection closes. A new one is refused only while all 128 carry calls
Calls on one connection1,000The client opens another connection to that node, up to 64
A producer's open attempt5 sThe client tries the next address, within the retry budget
Cached tokens64The oldest is forgotten, and asked for again when needed

See also

On this page