I wrote a small library called Kite a couple of years back, based on Michael Nygard’s outstanding book. Currently it has a and concurrency throttle. There are several others I’d like to add. [Update: I've since added a rate-limiting throttle.] It’s something I’ll get back to once I finish the book.
So today I moved Kite from Google Code to GitHub. Check out my .
Kite includes a tiny sample app so you can see how it works. But it’s pretty easy to describe just in a blog post. Kite allows you to harden your app in a couple of easy steps. First:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="/schema/kite"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
/schema/kite /schema/kite/kite-1.0-a3.xsd">
<!-- Activate Kite annotations -->
<annotation-config />
<!-- Message service -->
<circuit-breaker id="messageServiceBreaker" exceptionThreshold="3" timeout="30000" />
<throttle id="messageServiceThrottle" limit="50" />
<!-- Expose components as JMX MBeans (optional) -->
<context:mbean-export />
</beans:beans>
And second, here’s the message service itself:
import org.zkybase.kite.GuardedBy;
... other imports ...
@Service
@Transactional
public class MessageService {
@GuardedBy({ "messageServiceThrottle", "messageServiceBreaker" })
public Message getMotd() { ... }
@GuardedBy({ "messageServiceThrottle", "messageServiceBreaker" })
public List getImportantMessages() { ... }
}
After this, your service methods are protected by a circuit breaker that trips if there are three consecutive errors (“trip” here means that it disables the call), and a concurrency throttle that throws an exception if there are 50 concurrent requests. Such components protect both the backend service and also clients that want to avoid queuing on services that are experiencing performance degradation.
For more information on how the circuit breaker works, see .
I’ll do a more careful writeup later, but and send any questions or feedback my way.