In my Java application I am establishing KDB connection using
private void initConnection() throws KException, IOException { conn = new c(host, port); conn.tz = TimeZone.getTimeZone(CONNECTION_TIMEZONE);}
Then I use conn
for inserting data asynchronously in tables successfully.
KDB server is restarted once in week and at that time as connection is reset by server I am getting an exception java.net.SocketException
.
Using the above exception I can again re-establish lost connection but this is not a decent solution as I lose batch etc. and I dont want connection exception to be thrown at the time of data insertion.
Instead, is there a call-back/listener/exception method in KDB Java API where API can inform java application upfront if a connection is closed by server / lost?
There’s no Java API as such that will automatically detect when the server connection is broken. The only way to do it would be to (a) push a “heartbeat” from/to the server and try to reconnect or (b) try/catch on insertion, and populate a Queue on Java side when it fails, so you don’t lose the batch.
Or… you know when the server gets restarted. So you could have a timer task that just re-establishes the connection at the right time. That’s a bit hacky.
There is a way you can create your own heartbeat from KDB process, when the Java client start and create the KDB connection, you can call a function and passing the handle ( .z.w ) to KDB process, say, in a dictionary.
Then the KDB process can setup a timer and publish some heartbeat message to Java client, if that get lost, the Java client can restart the connection or maybe failover to some other KDB process
See if that help.