Use it for Kubernetes liveness & readiness checks. The middleware opens a HTTP server on port 3001. To check, open the http://localhost:3001/live & http://localhost:3001/ready URL.
{
"state": "up",
"uptime": 7.419,
"timestamp": 1562790370161
}
The
state
can be"starting"
(503),"up"
(200),"stopping"
(503) or"down"
(503).
Load with default options
// moleculer.config.js
const HealthMiddleware = require("./health-check.middleware.js");
module.exports = {
middlewares: [
HealthMiddleware()
]
};
Load with custom options
// moleculer.config.js
const HealthMiddleware = require("./health-check.middleware.js");
module.exports = {
middlewares: [
HealthMiddleware({
port: 3333,
readiness: {
path: "/ready"
},
liveness: {
path: "/live"
}
})
]
};
apiVersion: apps/v1
kind: Deployment
metadata:
name: greeter
spec:
selector:
matchLabels:
app: greeter
replicas: 1
template:
metadata:
labels:
app: greeter
spec:
containers:
- name: greeter
image: moleculer/demo:1.4.2
livenessProbe:
httpGet:
path: /live
port: 3001
readinessProbe:
httpGet:
path: /ready
port: 3001
Yeah,
$node.disconnected
withunexpected: true
is called when heartbeat not received from a remote node.https://github.com/moleculerjs/moleculer/blob/master/src/registry/node-catalog.js#L191
It's a local event, so you can also subscribe to it as
broker.localBus.on("$node.disconnected", () => {})
in a middleware