Search code examples
hyperledger-fabrichyperledgerhyperledger-fabric-sdk-js

How to look if peers and orderers are active from Fabric Node SDK


I want to check from my Node SDK if peers and orderers are active before send transactions to them. Essentially I want to implement a sort of Healthcheck for my server. If a peer is down, I don't even want to make a transaction proposal and contact other peers.

I could create on the chaincode an healthcheck endpoint but I don't want to invoke the chaincode. I would just want to connect to the peer and check if the connection succeed. If succeed, it means the peer is alive, otherwise not.

How to do this from fabric SDK? Of course I would do this for peer but would be helpful for orderers too.


Solution

  • For peers and orderers, you can poll the nodes via the operations /healthz REST endpoint.

    If a peer is down, I don't even want to make a transaction proposal and contact other peers.

    Keep in mind that if you use service discovery then you only need to monitor your peers used for discovery, and you can ask these peers for endorsers and they will not send back endpoints of peers that are offline.