Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Add changes to support providing time configs in milliseconds #51

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ private ConnectionConfiguration getConnectionConfigFromContext(MessageContext ms
connectionConfig.setAwsAccessKeyId(awsAccessKeyId);
connectionConfig.setAwsSecretAccessKey(awsSecretAccessKey);
if (StringUtils.isNotBlank(socketTimeout)) {
connectionConfig.setSocketTimeout(Integer.valueOf(socketTimeout));
connectionConfig.setSocketTimeout(Utils.convertToMillis(socketTimeout));
}
if (StringUtils.isNotBlank(connectionTimeout)) {
connectionConfig.setConnectionTimeout(Integer.valueOf(connectionTimeout));
connectionConfig.setConnectionTimeout(Utils.convertToMillis(connectionTimeout));
}
if (StringUtils.isNotBlank(connectionMaxIdleTime)) {
connectionConfig.setConnectionMaxIdleTime(Integer.valueOf(connectionMaxIdleTime));
connectionConfig.setConnectionMaxIdleTime(Utils.convertToMillis(connectionMaxIdleTime));
}
if (StringUtils.isNotBlank(connectionTimeToLive)) {
connectionConfig.setConnectionTimeToLive(Integer.valueOf(connectionTimeToLive));
connectionConfig.setConnectionTimeToLive(Utils.convertToMillis(connectionTimeToLive));
}
if (StringUtils.isNotBlank(connectionAcquisitionTimeout)) {
connectionConfig.setConnectionAcquisitionTimeout(Integer.valueOf(connectionAcquisitionTimeout));
connectionConfig.setConnectionAcquisitionTimeout(Utils.convertToMillis(connectionAcquisitionTimeout));
}
if (StringUtils.isNotBlank(apiCallTimeout)) {
connectionConfig.setApiCallTimeout(Integer.valueOf(apiCallTimeout));
connectionConfig.setApiCallTimeout(Utils.convertToMillis(apiCallTimeout));
}
if (StringUtils.isNotBlank(apiCallAttemptTimeout)) {
connectionConfig.setApiCallAttemptTimeout(Integer.valueOf(apiCallAttemptTimeout));
connectionConfig.setApiCallAttemptTimeout(Utils.convertToMillis(apiCallAttemptTimeout));
}
return connectionConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ private SqsClient createNewClientInstance(ConnectionConfiguration connectionConf
Integer apiCallAttemptTimeout = connectionConfig.getApiCallAttemptTimeout();
ApacheHttpClient.Builder apacheHttpClientBuilder = ApacheHttpClient.builder();
if (connectionTimeout != -1) {
apacheHttpClientBuilder.connectionTimeout(Duration.ofSeconds(connectionTimeout));
apacheHttpClientBuilder.connectionTimeout(Duration.ofMillis(connectionTimeout));
}
if (connectionAcquisitionTimeout != -1) {
apacheHttpClientBuilder.connectionAcquisitionTimeout(Duration.ofSeconds(connectionAcquisitionTimeout));
apacheHttpClientBuilder.connectionAcquisitionTimeout(Duration.ofMillis(connectionAcquisitionTimeout));
}
if (socketTimeout != -1) {
apacheHttpClientBuilder.socketTimeout(Duration.ofSeconds(socketTimeout));
apacheHttpClientBuilder.socketTimeout(Duration.ofMillis(socketTimeout));
}
if (connectionTimeToLive != -1) {
apacheHttpClientBuilder.connectionTimeToLive(Duration.ofSeconds(connectionTimeToLive));
apacheHttpClientBuilder.connectionTimeToLive(Duration.ofMillis(connectionTimeToLive));
}
if (connectionMaxIdleTime != -1) {
apacheHttpClientBuilder.connectionMaxIdleTime(Duration.ofSeconds(connectionMaxIdleTime));
apacheHttpClientBuilder.connectionMaxIdleTime(Duration.ofMillis(connectionMaxIdleTime));
}
SqsClientBuilder sqsClientBuilder = SqsClient.builder().region(Region.of(connectionConfig.getRegion())).
httpClient(apacheHttpClientBuilder.build());
Expand All @@ -96,11 +96,11 @@ private SqsClient createNewClientInstance(ConnectionConfiguration connectionConf
create(awsAccessKeyId, awsSecretAccessKey));
}
if (apiCallTimeout != -1) {
sqsClientBuilder.overrideConfiguration(b -> b.apiCallTimeout(Duration.ofSeconds(apiCallTimeout)));
sqsClientBuilder.overrideConfiguration(b -> b.apiCallTimeout(Duration.ofMillis(apiCallTimeout)));
}
if (apiCallAttemptTimeout != -1) {
sqsClientBuilder.overrideConfiguration(b -> b.apiCallAttemptTimeout(
Duration.ofSeconds(apiCallAttemptTimeout)));
Duration.ofMillis(apiCallAttemptTimeout)));
}
return sqsClientBuilder.credentialsProvider(credentialsProvider).build();
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/wso2/carbon/connector/amazonsqs/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import software.amazon.awssdk.services.sqs.model.SqsResponseMetadata;

import javax.xml.stream.XMLStreamException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
Expand Down Expand Up @@ -335,11 +336,22 @@ public static AwsRequestOverrideConfiguration.Builder getOverrideConfiguration(S
throws NumberFormatException {
AwsRequestOverrideConfiguration.Builder overrideConfiguration = AwsRequestOverrideConfiguration.builder();
if (StringUtils.isNotBlank(apiCallTimeout)) {
overrideConfiguration.apiCallTimeout(Duration.ofSeconds(Integer.parseInt(apiCallTimeout)));
overrideConfiguration.apiCallTimeout(Duration.ofMillis(convertToMillis(apiCallTimeout)));
}
if (StringUtils.isNotBlank(apiCallAttemptTimeout)) {
overrideConfiguration.apiCallAttemptTimeout(Duration.ofSeconds(Integer.parseInt(apiCallAttemptTimeout)));
overrideConfiguration.apiCallAttemptTimeout(Duration.ofMillis(convertToMillis(apiCallAttemptTimeout)));
}
return overrideConfiguration;
}

/**
* Convert given duration in seconds to milliseconds
*
* @param duration - duration in seconds
* @return integer
*/
public static Integer convertToMillis(String duration) {
double seconds = Double.parseDouble(duration);
return (int) (seconds * 1000);
}
}