Skip to content

Commit 45d55ed

Browse files
committed
Add support for AWS CRT Client
1 parent 036953d commit 45d55ed

File tree

7 files changed

+185
-0
lines changed

7 files changed

+185
-0
lines changed

aws-sdk-v2/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies {
1212
compileOnly(libs.awssdk.url.connection.client)
1313
compileOnly(libs.awssdk.netty.nio.client)
1414
compileOnly(libs.awssdk.apache.client)
15+
compileOnly(libs.awssdk.aws.crt.client)
1516

1617
// Services
1718
compileOnly(libs.awssdk.apigatewaymanagementapi)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2017-2020 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micronaut.aws.sdk.v2.client.crt;
17+
18+
import io.micronaut.aws.AWSConfiguration;
19+
import io.micronaut.context.annotation.BootstrapContextCompatible;
20+
import io.micronaut.context.annotation.ConfigurationBuilder;
21+
import io.micronaut.context.annotation.ConfigurationProperties;
22+
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
23+
import software.amazon.awssdk.http.crt.ProxyConfiguration;
24+
25+
/**
26+
* Configuration properties for the Netty async client.
27+
*
28+
* @author Luis Duarte
29+
* @since 4.12.x
30+
*/
31+
@ConfigurationProperties(AwsCrtClientConfiguration.PREFIX)
32+
@BootstrapContextCompatible
33+
public class AwsCrtClientConfiguration extends AWSConfiguration {
34+
35+
public static final String PREFIX = "aws-crt-client";
36+
37+
@ConfigurationBuilder(prefixes = {""}, excludes = {"proxyConfiguration", "buildWithDefaults", "applyMutation"})
38+
private AwsCrtAsyncHttpClient.Builder builder = AwsCrtAsyncHttpClient.builder();
39+
40+
@ConfigurationBuilder(configurationPrefix = "proxy", prefixes = {""}, excludes = {"applyMutation", "copy"})
41+
private ProxyConfiguration.Builder proxy = ProxyConfiguration.builder();
42+
43+
/**
44+
* @return The builder for {@link AwsCrtAsyncHttpClient}
45+
*/
46+
public AwsCrtAsyncHttpClient.Builder getBuilder() {
47+
return builder.proxyConfiguration(proxy.build());
48+
}
49+
50+
/**
51+
* @return The builder for {@link ProxyConfiguration}
52+
*/
53+
public ProxyConfiguration.Builder getProxy() {
54+
return proxy;
55+
}
56+
57+
boolean isProxyConfigured() {
58+
ProxyConfiguration proxyConfig = proxy.build();
59+
return proxyConfig.host() != null;
60+
}
61+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017-2025 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micronaut.aws.sdk.v2.client.crt;
17+
18+
import io.micronaut.context.annotation.Bean;
19+
import io.micronaut.context.annotation.BootstrapContextCompatible;
20+
import io.micronaut.context.annotation.Factory;
21+
import io.micronaut.context.annotation.Requires;
22+
import jakarta.inject.Singleton;
23+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
24+
25+
@Factory
26+
@BootstrapContextCompatible
27+
public class AwsCrtClientFactory {
28+
public static final String ASYNC_SERVICE_IMPL = "software.amazon.awssdk.http.async.service.impl";
29+
public static final String AWS_CRT_SDK_ASYNC_HTTP_SERVICE = "software.amazon.awssdk.http.crt.AwsCrtSdkHttpService";
30+
31+
/**
32+
* @param configuration The AWS CRT client configuration
33+
* @return an instance of {@link SdkAsyncHttpClient}
34+
*/
35+
@Bean(preDestroy = "close")
36+
@Singleton
37+
public SdkAsyncHttpClient awsCrtClient(AwsCrtClientConfiguration configuration) {
38+
return doCreateClient(configuration);
39+
}
40+
41+
/**
42+
* @param configuration The AWS CRT client configuration
43+
* @return an instance of {@link SdkAsyncHttpClient}
44+
*/
45+
@Bean(preDestroy = "close")
46+
@Singleton
47+
@Requires(property = ASYNC_SERVICE_IMPL, value = AWS_CRT_SDK_ASYNC_HTTP_SERVICE)
48+
public SdkAsyncHttpClient systemPropertyClient(AwsCrtClientConfiguration configuration) {
49+
return doCreateClient(configuration);
50+
}
51+
52+
private SdkAsyncHttpClient doCreateClient(AwsCrtClientConfiguration configuration) {
53+
return configuration.getBuilder().build();
54+
}
55+
56+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2017-2020 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
/**
17+
* AWS CRT client configuration and factory.
18+
*
19+
* @author Luis Duarte
20+
* @since 4.12.x
21+
*/
22+
@Requires(classes = AwsCrtAsyncHttpClient.class)
23+
@Configuration
24+
package io.micronaut.aws.sdk.v2.client.crt;
25+
26+
import io.micronaut.context.annotation.Configuration;
27+
import io.micronaut.context.annotation.Requires;
28+
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.micronaut.aws.sdk.v2.client.crt
2+
3+
import io.micronaut.context.ApplicationContext
4+
import io.micronaut.context.annotation.BootstrapContextCompatible
5+
import spock.lang.Specification
6+
7+
class AwsCrtClientConfigurationSpec extends Specification {
8+
9+
void 'AwsCrtClientConfiguration is annotated with BootstrapContextCompatible'() {
10+
given:
11+
ApplicationContext context = ApplicationContext.run()
12+
13+
expect:
14+
context.getBeanDefinition(AwsCrtClientConfiguration).getAnnotationNameByStereotype(BootstrapContextCompatible).isPresent()
15+
16+
cleanup:
17+
context.close()
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.micronaut.aws.sdk.v2.client.crt
2+
3+
import io.micronaut.context.ApplicationContext
4+
import io.micronaut.context.annotation.BootstrapContextCompatible
5+
import spock.lang.Specification
6+
7+
class AwsCrtClientFactorySpec extends Specification {
8+
9+
void 'AwsCrtClientFactory is annotated with BootstrapContextCompatible'() {
10+
given:
11+
ApplicationContext context = ApplicationContext.run()
12+
13+
expect:
14+
context.getBeanDefinition(AwsCrtClientFactory).getAnnotationNameByStereotype(BootstrapContextCompatible).isPresent()
15+
16+
cleanup:
17+
context.close()
18+
}
19+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ awssdk-sqs = { module = 'software.amazon.awssdk:sqs' }
7979
awssdk-ssm = { module = 'software.amazon.awssdk:ssm' }
8080
awssdk-iam = { module = 'software.amazon.awssdk:iam' }
8181
awssdk-url-connection-client = { module = 'software.amazon.awssdk:url-connection-client' }
82+
awssdk-aws-crt-client = { module = 'software.amazon.awssdk:aws-crt-client' }
8283

8384
kotlin-stdlib-jdk8 = { module = 'org.jetbrains.kotlin:kotlin-stdlib-jdk8', version.ref = 'kotlin' }
8485

0 commit comments

Comments
 (0)