@@ -32,6 +32,7 @@ public class RateLimiterProcessor implements BridgeEventProcessor {
3232 private int mMaximumSize = 50000 ;
3333 private int mExpireAfterAccess = 3600 ;
3434 private boolean mEnable = true ;
35+ private boolean mWarningOnly = true ;
3536 private Logger mLog ;
3637
3738 @ StartService
@@ -61,14 +62,16 @@ public Single<BridgeEventContext> process(Single<BridgeEventContext> pContext) {
6162
6263 Bucket bucket = getCache ().get (eventType ).get (ctx .getBridgeEvent ().socket ().writeHandlerID (), () -> {
6364 Refill refill = Refill .smooth (getRateOfTokenFill ().getOrDefault (eventType , getDefaultRateOfTokenFill ()),
64- Duration .ofSeconds (getRateOfTokenFillDuration ().getOrDefault (eventType , getDefaultRateOfTokenFillDuration ())));
65+ Duration .ofSeconds (getRateOfTokenFillDuration ().getOrDefault (eventType , getDefaultRateOfTokenFillDuration ())));
6566 Bandwidth limit = Bandwidth .classic (getTokenBucketSize ().getOrDefault (eventType , getDefaultTokenBucketSize ()), refill );
6667 return Bucket4j .builder ().addLimit (limit ).build ();
6768 });
6869
6970 if (!bucket .tryConsume (1 )) {
70- getLog ().debug (() -> String .format ("[%s] Rate limit crossed for connection:[%s],event:[%s]" , ctx .getId (), ctx .getBridgeEvent ().socket ().writeHandlerID (), eventType .toString ()));
71- ctx .getBridgeEvent ().fail ("Rate Limit Crossed" );
71+ if (!isWarningOnly ()) {
72+ ctx .getBridgeEvent ().fail ("Rate Limit Crossed" );
73+ }
74+ getLog ().warn (() -> String .format ("[%s] Rate limit crossed for connection:[%s],event:[%s]" , ctx .getId (), ctx .getBridgeEvent ().socket ().writeHandlerID (), eventType .toString ()));
7275 }
7376
7477 return ctx ;
@@ -181,4 +184,12 @@ public void setDefaultRateOfTokenFillDuration(int pDefaultRateOfTokenFillDuratio
181184 this .mDefaultRateOfTokenFillDuration = pDefaultRateOfTokenFillDuration ;
182185 }
183186
187+ public boolean isWarningOnly () {
188+ return mWarningOnly ;
189+ }
190+
191+ public void setWarningOnly (boolean pWarningOnly ) {
192+ this .mWarningOnly = pWarningOnly ;
193+ }
194+
184195}
0 commit comments