February 2017
Intermediate to advanced
1023 pages
24h 11m
English
Adding a new custom module to the Spring Boot application is not so complex. To demonstrate this feature, assume that if a service gets more than two transactions in a minute, then the server status will be set as Out of Service.
In order to customize this, we have to implement the HealthIndicator interface and override the health method. The following is a quick and dirty implementation to do the job:
class TPSCounter { LongAdder count; int threshold = 2; Calendar expiry = null; TPSCounter(){ this.count = new LongAdder(); this.expiry = Calendar.getInstance(); this.expiry.add(Calendar.MINUTE, 1); } boolean isExpired(){ return Calendar.getInstance().after(expiry); } boolean isWeak(){ return (count.intValue() > threshold); ...Read now
Unlock full access