Connecting
To establish an Aerospike server connection, create an AerospikeClient
object by providing the IP address and port of one cluster node. This IP address is used to initiate contact to the cluster, and the client can then discover the entire cluster.
AerospikeClient client = new AerospikeClient("127.0.0.1", 3000);
The AerospikeClient
constructor creates a maintenance thread that periodically pings nodes for cluster status.
On a network disturbance where the client can no longer reach any nodes, the seed nodes (and the discovered friend nodes on initial connection) are pinged until client-server connection is reestablished.
The AerospikeClient
instance is thread-safe and can be used concurrently. Each get/set
call is a blocking, synchronous network call to Aerospike. Connections are cached with a connection pool for each server node.
TLS secured connection
TLS connections require certificate configuration on both client and server. The TLS connection port is usually set to 4333 instead of the typically unsecured port 3000.
The client TLS name (clusterTLSName
in this example) should match
either the certificate common name (CN) or the certificate subject alternative
name. Usually, the client TLS name is also the server’s
tls-name
configuration value.
The TlsPolicy can also be configured to limit protocols or ciphers and revoke certificates. See TLS configuration for more information about setting up TLS on your Aerospike Database server. See the API documentation for client TLS configuration options.
using Aerospike.Client;
// TLS secured connectionHost host = new("192.168.10.10", "clusterTLSName", 4333);
TlsPolicy tlsPolicy = new();
ClientPolicy policy = new(){ tlsPolicy = tlsPolicy};
AerospikeClient client = new(policy, host);
// TLS secured conneciton with PKI authenticationHost host = new("192.168.10.10", "clusterTLSName", 4333);
TlsPolicy tlsPolicy = new();
ClientPolicy policy = new(){ tlsPolicy = tlsPolicy, authMode = AuthMode.PKI};
AerospikeClient client = new(policy, host);
Cleaning Up
Call Close()
when all commands are finished and the application is ready to shutdown.
client.Close();