1

I am using cassandra-driver module in node.js. My usecase is that I have emit notification in the UI saying "DB is in down state" when Cassandra node goes down due to some reason.

Basically, I should be able to capture the information as soon as the casssandra goes down using cassandra-driver in node.js

Any help is appreciated .

unnamed-bull
  • 361
  • 4
  • 15

2 Answers2

0

You can either periodically check the client.hosts for nodes that are down. Or maybe it's better to define hooks like hostDown, etc., and use them to decide if cluster is not available.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Thanks Alex, client.hosts does not work if a node is down after some point of time. Can you give code example of hostDown hooks etc it will be helpful. Thanks in Advance. – unnamed-bull Jan 06 '20 at 04:32
0

client.hosts does not work, for the temporary solution I am using

client.on('log', (level, className, message, furtherInfo) => {

if(level === 'error' && ['NoHostAvailableError', 'OperationTimedOutError'].includes(furtherInfo.name)) {

emitNotification('DB_IS_DOWN');

});

If any one has better solution, you are highly welcome.

Note: This solution works for me very well !!

unnamed-bull
  • 361
  • 4
  • 15