3

I need to make persistance connection to Aerospike noSQL DB in a Web service.

In a not-Web application, connection is straightfoward as

using (AerospikeClient client = new AerospikeClient("127.0.0.1", 3000)) 
{
...
}

But in a Web service application, creating new client for each request is expensive. The Best Practices say this too: "use only one client instance per cluster in a program and share that instance among multiple threads. AerospikeClient and AsyncClient are thread-safe."

I can make a static object, but what if the client disconnects, either by error or timeout (24 hours max connection living time)? Can anyone provide any fault-tolerant code spippet? (Maybe similar to redis pattern How does ConnectionMultiplexer deal with disconnects?)

Community
  • 1
  • 1
yatskovsky
  • 1,168
  • 1
  • 7
  • 10

1 Answers1

3

The client manages a socket pool. If a socket error or timeout occurs, the socket is disposed of.

kporter
  • 2,684
  • 17
  • 26
  • So, is it safe to merely write 'public static AsyncClient client = new AsyncClient(policy, host, port);' and use it 24/7? – yatskovsky Sep 21 '15 at 12:52
  • Thanks. I also should add failIfNotConnected = false to the policy, otherwise I risk to get TypeInitializationException. – yatskovsky Sep 21 '15 at 16:27