public class RateLimiter extends HttpMiddleware implements HttpConstants
route.use(new RateLimiter(100, true));
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
applyForAll
Apply the performance cutoff for each service (= true), otherwise (=
false) it will only limit the load with the Actions marked with the
'RateLimit' annotation.
|
protected boolean |
headers
Add headers to all HTTP response (eg.
|
protected long |
limit
Default rate limit
|
protected RatingStoreFactory |
storeFactory
Hits per IP-addresses store
|
protected java.util.concurrent.TimeUnit |
unit
Unit of the time window/frame
|
protected long |
window
Time "window" (time frame) length
|
static java.lang.String |
X_HEADER_LIMIT |
static java.lang.String |
X_HEADER_REMAINING |
static java.lang.String |
X_HEADER_RESET |
ACCEPT, ACCEPT_ENCODING, AUTHORIZATION, CACHE_CONTROL, CHUNKED, CLOSE, CONNECT, CONNECTION, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, CONTENT_TYPE_HTML, CONTENT_TYPE_JSON, COOKIE, DEFLATE, DELETE, ETAG, GET, GZIP, HEAD, IF_NONE_MATCH, KEEP_ALIVE, LOCATION, META_CONTENT_TYPE, META_HEADERS, META_LOCALE, META_LOCATION, META_SESSION, META_STATUS, META_TEMPLATE, NO_CACHE, OPTIONS, PATCH, POST, PROPERTY_COOKIES, PROPERTY_SESSION_ID, PROPERTY_USER, PUT, SET_COOKIE, TRACE, TRANSFER_ENCODING, WWW_AUTHENTICATE, X_FORWARDED_FOR| Constructor and Description |
|---|
RateLimiter()
Creates a RateLimiter with default settings (50 requests / second for all
URLs).
|
RateLimiter(boolean applyForAll)
Creates a RateLimiter.
|
RateLimiter(int rateLimit,
boolean applyForAll) |
RateLimiter(int rateLimit,
int window,
java.util.concurrent.TimeUnit unit,
boolean applyForAll) |
| Modifier and Type | Method and Description |
|---|---|
long |
getRateLimit() |
RatingStoreFactory |
getStoreFactory() |
java.util.concurrent.TimeUnit |
getUnit() |
long |
getWindow() |
RequestProcessor |
install(RequestProcessor next,
io.datatree.Tree config) |
boolean |
isApplyForAll() |
boolean |
isHeaders() |
void |
setApplyForAll(boolean applyForAll) |
void |
setHeaders(boolean headers) |
void |
setRateLimit(long rateLimit) |
void |
setStoreFactory(RatingStoreFactory storeFactory) |
void |
setUnit(java.util.concurrent.TimeUnit unit) |
void |
setWindow(long window) |
void |
started(services.moleculer.ServiceBroker broker) |
void |
stopped() |
public static final java.lang.String X_HEADER_LIMIT
public static final java.lang.String X_HEADER_REMAINING
public static final java.lang.String X_HEADER_RESET
protected boolean applyForAll
protected long limit
protected long window
protected boolean headers
protected java.util.concurrent.TimeUnit unit
protected RatingStoreFactory storeFactory
public RateLimiter()
public RateLimiter(boolean applyForAll)
applyForAll - apply the performance cutoff for each service (= true),
otherwise (= false) it will only limit the load with the
Actions marked with the 'RateLimit' annotation.public RateLimiter(int rateLimit,
boolean applyForAll)
public RateLimiter(int rateLimit,
int window,
java.util.concurrent.TimeUnit unit,
boolean applyForAll)
public void started(services.moleculer.ServiceBroker broker)
throws java.lang.Exception
started in interface services.moleculer.service.MoleculerLifecyclestarted in class services.moleculer.service.MoleculerComponentjava.lang.Exceptionpublic RequestProcessor install(RequestProcessor next, io.datatree.Tree config)
install in class HttpMiddlewarepublic void stopped()
stopped in interface services.moleculer.service.MoleculerLifecyclestopped in class services.moleculer.service.MoleculerComponentpublic boolean isApplyForAll()
public void setApplyForAll(boolean applyForAll)
public long getRateLimit()
public void setRateLimit(long rateLimit)
public long getWindow()
public void setWindow(long window)
public java.util.concurrent.TimeUnit getUnit()
public void setUnit(java.util.concurrent.TimeUnit unit)
public RatingStoreFactory getStoreFactory()
public void setStoreFactory(RatingStoreFactory storeFactory)
public boolean isHeaders()
public void setHeaders(boolean headers)