Implemented heartbeat on Middleware to reconnect to RMs.