Skip to content

Commit

Permalink
Add broker request wait margin configuration (`merloc.broker.request.…
Browse files Browse the repository at this point in the history
…wait.margin`)
  • Loading branch information
Serkan ÖZAL committed Dec 15, 2022
1 parent 2d275c8 commit 49b18ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface ConfigNames extends io.thundra.merloc.aws.lambda.core.config.Co
String ENABLE = "merloc.enable";
String BROKER_URL_CONFIG_NAME = "merloc.broker.url";
String BROKER_CONNECTION_NAME_CONFIG_NAME = "merloc.broker.connection.name";
String BROKER_REQUEST_WAIT_MARGIN_CONFIG_NAME = "merloc.broker.request.wait.margin";
String API_KEY_CONFIG_NAME = "merloc.apikey";
String CLIENT_ACCESS_INTERVAL_ON_FAILURE = "merloc.client.access.interval.on.failure";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public class GateKeeperLambdaHandler extends WrapperLambdaHandler {
private static final String AWS_LAMBDA_CLIENT_CONTEXT_ATTRIBUTE_NAME = "clientContext";
private static final String AWS_LAMBDA_COGNITO_IDENTITY_ATTRIBUTE_NAME = "cognitoIdentity";
private static final String AWS_LAMBDA_REQUEST_ATTRIBUTE_NAME = "request";


private static final int DEFAULT_BROKER_REQUEST_WAIT_MARGIN = 1000;

private static final boolean ENABLE =
ConfigManager.getBooleanConfig(ConfigNames.ENABLE, true);
private static final String BROKER_URL =
Expand All @@ -75,6 +77,10 @@ public class GateKeeperLambdaHandler extends WrapperLambdaHandler {
ConfigManager.getConfig(
ConfigNames.BROKER_CONNECTION_NAME_CONFIG_NAME,
LambdaUtils.getEnvVar(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR_NAME));
private static final int BROKER_REQUEST_WAIT_MARGIN =
ConfigManager.getIntegerConfig(
ConfigNames.BROKER_REQUEST_WAIT_MARGIN_CONFIG_NAME,
DEFAULT_BROKER_REQUEST_WAIT_MARGIN);
private static final String API_KEY =
ConfigManager.getConfig(ConfigNames.API_KEY_CONFIG_NAME);
private static final int CLIENT_ACCESS_INTERVAL_ON_FAILURE =
Expand Down Expand Up @@ -213,7 +219,8 @@ protected boolean onRequest(InputStream requestStream, OutputStream responseStre
BrokerMessage clientResponse =
brokerClient.sendAndGetResponse(
clientRequest,
context.getRemainingTimeInMillis(), TimeUnit.MILLISECONDS);
Math.max(context.getRemainingTimeInMillis() - BROKER_REQUEST_WAIT_MARGIN, 0),
TimeUnit.MILLISECONDS);
if (clientResponse == null) {
// No response neither from client nor from broker.
// So update the latest client access fail time.
Expand Down

0 comments on commit 49b18ea

Please sign in to comment.