Skip to content

Commit

Permalink
Merge pull request #51 from AmilaSamith/patch-1218
Browse files Browse the repository at this point in the history
[PATCH] Add changes to support providing time configs in milliseconds
  • Loading branch information
SanojPunchihewa authored Oct 23, 2024
2 parents 19128b0 + e945625 commit 0b63b11
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .connector-store/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"releases": [
{
"tagName": "v2.0.0",
"tagName": "v2.0.1",
"products": [
"MI 4.3.0",
"MI 4.2.0",
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ The Amazon SQS connector allows you to access the exposed API through the WSO2 E

## Compatibility

| Connector version | Supported WSO2 ESB/EI version |
| ------------- |------------- |
| Connector version | Supported WSO2 ESB/EI version |
|--------------------------------------------------------------------------------------------------------------------|------------- |
| [2.0.1](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/v2.0.1) | MI 4.3.0 |
| [2.0.0](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/v2.0.0) | MI 4.3.0 |
| [1.1.0](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/v1.1.0) | EI 7.0.x, EI 6.6.0, EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.8](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/v1.0.8) | EI 7.0.x, EI 6.6.0, EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.7](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/org.wso2.carbon.connector.amazonsqs-1.0.7) | EI 7.0.x, EI 6.6.0, EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.6](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/org.wso2.carbon.connector.amazonsqs-1.0.6) | EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.5](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/org.wso2.carbon.connector.amazonsqs-1.0.5) | EI 6.1.1, ESB 5.0.0, ESB 4.9.0 |
| [1.1.0](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/v1.1.0) | EI 7.0.x, EI 6.6.0, EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.8](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/v1.0.8) | EI 7.0.x, EI 6.6.0, EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.7](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/org.wso2.carbon.connector.amazonsqs-1.0.7) | EI 7.0.x, EI 6.6.0, EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.6](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/org.wso2.carbon.connector.amazonsqs-1.0.6) | EI 6.4.0, EI 6.3.0, EI 6.1.1 |
| [1.0.5](https://github.com/wso2-extensions/esb-connector-amazonsqs/tree/org.wso2.carbon.connector.amazonsqs-1.0.5) | EI 6.1.1, ESB 5.0.0, ESB 4.9.0 |

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.connector</groupId>
<artifactId>org.wso2.carbon.connector.amazonsqs</artifactId>
<packaging>jar</packaging>
<version>2.0.0</version>
<version>2.0.1</version>
<name>WSO2 Carbon - Mediation Library Connector For amazonsqs</name>
<url>http://wso2.org</url>
<properties>
Expand Down
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);
}
}

0 comments on commit 0b63b11

Please sign in to comment.