36
36
import org .springframework .context .annotation .Conditional ;
37
37
import org .springframework .context .annotation .Configuration ;
38
38
import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
39
+ import software .amazon .awssdk .enhanced .dynamodb .DynamoDbEnhancedAsyncClient ;
39
40
import software .amazon .awssdk .enhanced .dynamodb .DynamoDbEnhancedClient ;
40
41
import software .amazon .awssdk .regions .providers .AwsRegionProvider ;
42
+ import software .amazon .awssdk .services .dynamodb .DynamoDbAsyncClient ;
43
+ import software .amazon .awssdk .services .dynamodb .DynamoDbAsyncClientBuilder ;
41
44
import software .amazon .awssdk .services .dynamodb .DynamoDbClient ;
42
45
import software .amazon .awssdk .services .dynamodb .DynamoDbClientBuilder ;
46
+ import software .amazon .dax .ClusterDaxAsyncClient ;
43
47
import software .amazon .dax .ClusterDaxClient ;
44
48
45
49
/**
51
55
*/
52
56
@ AutoConfiguration
53
57
@ EnableConfigurationProperties (DynamoDbProperties .class )
54
- @ ConditionalOnClass ({ DynamoDbClient .class , DynamoDbEnhancedClient . class , DynamoDbTemplate .class })
58
+ @ ConditionalOnClass ({ DynamoDbClient .class , DynamoDbAsyncClient .class })
55
59
@ AutoConfigureAfter ({ CredentialsProviderAutoConfiguration .class , RegionProviderAutoConfiguration .class })
56
60
@ ConditionalOnProperty (name = "spring.cloud.aws.dynamodb.enabled" , havingValue = "true" , matchIfMissing = true )
57
61
public class DynamoDbAutoConfiguration {
@@ -62,8 +66,9 @@ static class DaxDynamoDbClient {
62
66
63
67
@ ConditionalOnMissingBean
64
68
@ 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 {
67
72
DaxProperties daxProperties = properties .getDax ();
68
73
69
74
PropertyMapper propertyMapper = PropertyMapper .get ();
@@ -93,6 +98,39 @@ public DynamoDbClient dynamoDbClient(DynamoDbProperties properties, AwsCredentia
93
98
return ClusterDaxClient .builder ().overrideConfiguration (configuration .build ()).build ();
94
99
}
95
100
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
+ }
96
134
}
97
135
98
136
@ Conditional (MissingDaxUrlCondition .class )
@@ -101,20 +139,44 @@ static class StandardDynamoDbClient {
101
139
102
140
@ ConditionalOnMissingBean
103
141
@ Bean
104
- public DynamoDbClient dynamoDbClient (AwsClientBuilderConfigurer awsClientBuilderConfigurer ,
142
+ public DynamoDbClient standardDynamoDbClient (AwsClientBuilderConfigurer awsClientBuilderConfigurer ,
105
143
ObjectProvider <AwsClientCustomizer <DynamoDbClientBuilder >> configurer , DynamoDbProperties properties ) {
106
144
return awsClientBuilderConfigurer
107
145
.configure (DynamoDbClient .builder (), properties , configurer .getIfAvailable ()).build ();
108
146
}
109
147
110
148
}
111
149
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
+
112
165
@ ConditionalOnMissingBean
166
+ @ ConditionalOnClass (DynamoDbEnhancedClient .class )
113
167
@ Bean
114
168
public DynamoDbEnhancedClient dynamoDbEnhancedClient (DynamoDbClient dynamoDbClient ) {
115
169
return DynamoDbEnhancedClient .builder ().dynamoDbClient (dynamoDbClient ).build ();
116
170
}
117
171
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 )
118
180
@ ConditionalOnMissingBean (DynamoDbOperations .class )
119
181
@ Bean
120
182
public DynamoDbTemplate dynamoDBTemplate (DynamoDbProperties properties ,
0 commit comments