3636import org .springframework .context .annotation .Conditional ;
3737import org .springframework .context .annotation .Configuration ;
3838import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
39+ import software .amazon .awssdk .enhanced .dynamodb .DynamoDbEnhancedAsyncClient ;
3940import software .amazon .awssdk .enhanced .dynamodb .DynamoDbEnhancedClient ;
4041import software .amazon .awssdk .regions .providers .AwsRegionProvider ;
42+ import software .amazon .awssdk .services .dynamodb .DynamoDbAsyncClient ;
43+ import software .amazon .awssdk .services .dynamodb .DynamoDbAsyncClientBuilder ;
4144import software .amazon .awssdk .services .dynamodb .DynamoDbClient ;
4245import software .amazon .awssdk .services .dynamodb .DynamoDbClientBuilder ;
46+ import software .amazon .dax .ClusterDaxAsyncClient ;
4347import software .amazon .dax .ClusterDaxClient ;
4448
4549/**
5155 */
5256@ AutoConfiguration
5357@ EnableConfigurationProperties (DynamoDbProperties .class )
54- @ ConditionalOnClass ({ DynamoDbClient .class , DynamoDbEnhancedClient . class , DynamoDbTemplate .class })
58+ @ ConditionalOnClass ({ DynamoDbClient .class , DynamoDbAsyncClient .class })
5559@ AutoConfigureAfter ({ CredentialsProviderAutoConfiguration .class , RegionProviderAutoConfiguration .class })
5660@ ConditionalOnProperty (name = "spring.cloud.aws.dynamodb.enabled" , havingValue = "true" , matchIfMissing = true )
5761public class DynamoDbAutoConfiguration {
@@ -62,8 +66,9 @@ static class DaxDynamoDbClient {
6266
6367 @ ConditionalOnMissingBean
6468 @ Bean
65- public DynamoDbClient dynamoDbClient (DynamoDbProperties properties , AwsCredentialsProvider credentialsProvider ,
66- AwsRegionProvider regionProvider ) throws IOException {
69+ public DynamoDbClient daxDynamoDbClient (DynamoDbProperties properties ,
70+ AwsCredentialsProvider credentialsProvider ,
71+ AwsRegionProvider regionProvider ) throws IOException {
6772 DaxProperties daxProperties = properties .getDax ();
6873
6974 PropertyMapper propertyMapper = PropertyMapper .get ();
@@ -93,6 +98,39 @@ public DynamoDbClient dynamoDbClient(DynamoDbProperties properties, AwsCredentia
9398 return ClusterDaxClient .builder ().overrideConfiguration (configuration .build ()).build ();
9499 }
95100
101+ @ ConditionalOnMissingBean
102+ @ Bean
103+ public DynamoDbAsyncClient daxDynamoDbAsyncClient (DynamoDbProperties properties ,
104+ AwsCredentialsProvider credentialsProvider ,
105+ AwsRegionProvider regionProvider ) throws IOException {
106+ DaxProperties daxProperties = properties .getDax ();
107+
108+ PropertyMapper propertyMapper = PropertyMapper .get ();
109+ software .amazon .dax .Configuration .Builder configuration = software .amazon .dax .Configuration .builder ();
110+ propertyMapper .from (daxProperties .getIdleTimeoutMillis ()).whenNonNull ()
111+ .to (configuration ::idleTimeoutMillis );
112+ propertyMapper .from (daxProperties .getConnectionTtlMillis ()).whenNonNull ()
113+ .to (configuration ::connectionTtlMillis );
114+ propertyMapper .from (daxProperties .getConnectTimeoutMillis ()).whenNonNull ()
115+ .to (configuration ::connectTimeoutMillis );
116+ propertyMapper .from (daxProperties .getRequestTimeoutMillis ()).whenNonNull ()
117+ .to (configuration ::requestTimeoutMillis );
118+ propertyMapper .from (daxProperties .getWriteRetries ()).whenNonNull ().to (configuration ::writeRetries );
119+ propertyMapper .from (daxProperties .getReadRetries ()).whenNonNull ().to (configuration ::readRetries );
120+ propertyMapper .from (daxProperties .getClusterUpdateIntervalMillis ()).whenNonNull ()
121+ .to (configuration ::clusterUpdateIntervalMillis );
122+ propertyMapper .from (daxProperties .getEndpointRefreshTimeoutMillis ()).whenNonNull ()
123+ .to (configuration ::endpointRefreshTimeoutMillis );
124+ propertyMapper .from (daxProperties .getMaxConcurrency ()).whenNonNull ().to (configuration ::maxConcurrency );
125+ propertyMapper .from (daxProperties .getMaxPendingConnectionAcquires ()).whenNonNull ()
126+ .to (configuration ::maxPendingConnectionAcquires );
127+ propertyMapper .from (daxProperties .getSkipHostNameVerification ()).whenNonNull ()
128+ .to (configuration ::skipHostNameVerification );
129+
130+ configuration .region (AwsClientBuilderConfigurer .resolveRegion (properties , regionProvider ))
131+ .credentialsProvider (credentialsProvider ).url (properties .getDax ().getUrl ());
132+ return ClusterDaxAsyncClient .builder ().overrideConfiguration (configuration .build ()).build ();
133+ }
96134 }
97135
98136 @ Conditional (MissingDaxUrlCondition .class )
@@ -101,20 +139,44 @@ static class StandardDynamoDbClient {
101139
102140 @ ConditionalOnMissingBean
103141 @ Bean
104- public DynamoDbClient dynamoDbClient (AwsClientBuilderConfigurer awsClientBuilderConfigurer ,
142+ public DynamoDbClient standardDynamoDbClient (AwsClientBuilderConfigurer awsClientBuilderConfigurer ,
105143 ObjectProvider <AwsClientCustomizer <DynamoDbClientBuilder >> configurer , DynamoDbProperties properties ) {
106144 return awsClientBuilderConfigurer
107145 .configure (DynamoDbClient .builder (), properties , configurer .getIfAvailable ()).build ();
108146 }
109147
110148 }
111149
150+ @ Conditional (MissingDaxUrlCondition .class )
151+ @ Configuration (proxyBeanMethods = false )
152+ static class StandardDynamoDbAsyncClient {
153+
154+ @ ConditionalOnMissingBean
155+ @ Bean
156+ public DynamoDbAsyncClient standardDynamoDbAsyncClient (AwsClientBuilderConfigurer awsClientBuilderConfigurer ,
157+ ObjectProvider <AwsClientCustomizer <DynamoDbAsyncClientBuilder >> configurer ,
158+ DynamoDbProperties properties ) {
159+ return awsClientBuilderConfigurer
160+ .configure (DynamoDbAsyncClient .builder (), properties , configurer .getIfAvailable ()).build ();
161+ }
162+
163+ }
164+
112165 @ ConditionalOnMissingBean
166+ @ ConditionalOnClass (DynamoDbEnhancedClient .class )
113167 @ Bean
114168 public DynamoDbEnhancedClient dynamoDbEnhancedClient (DynamoDbClient dynamoDbClient ) {
115169 return DynamoDbEnhancedClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
116170 }
117171
172+ @ ConditionalOnMissingBean
173+ @ ConditionalOnClass (DynamoDbEnhancedAsyncClient .class )
174+ @ Bean
175+ public DynamoDbEnhancedAsyncClient dynamoDbEnhancedAsyncClient (DynamoDbAsyncClient dynamoDbClient ) {
176+ return DynamoDbEnhancedAsyncClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
177+ }
178+
179+ @ ConditionalOnClass (DynamoDbTemplate .class )
118180 @ ConditionalOnMissingBean (DynamoDbOperations .class )
119181 @ Bean
120182 public DynamoDbTemplate dynamoDBTemplate (DynamoDbProperties properties ,
0 commit comments