NodeCloud-Brakes
Usage
UserClient
;;const SERVICE_NAME = 'user-service';const brake = SERVICE_NAME;//set health check.brake;brake;brake;brake;{const request =method: 'get'url: `/v1/users/:userId`params: userId: userIdheaders:'Content-Type': 'application/json';return brake;}
You can use brake client to invoke resource api. The example is
;userClient
API
new BrakeClient(serviceName, options)
serviceName
The service name.
options
The options param is the same as brakes. We extend it, and support request handlers
- options.handler.preHandle(request)
- options.handler.postHandle(err, response)
- options.handler.postCircuit(response);
brake.healthCheck(callback)
Set a callback, when the circuit is open, the callback will be used for checking the service's health status, if the status is ok, the circuit will close.
brake.on(eventName, callback)
See brakes for detail.
brake.isOpen()
Return the circuit's status.
brake.circuit(client, fallback, options) : {send(request)}
- client: (required) an object implement send function.
- fallback: (optional) fallback function.
- options (optional) the same as brakes.
brake.fallback(callback)
- fallback: (optional) the global fallback function.