io.quarkus.amazon.dynamodb.runtime.DynamodbRecorder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-amazon-dynamodb Show documentation
Show all versions of quarkus-amazon-dynamodb Show documentation
Connect to Amazon DynamoDB datastore
package io.quarkus.amazon.dynamodb.runtime;
import io.quarkus.amazon.common.runtime.AwsConfig;
import io.quarkus.amazon.common.runtime.NettyHttpClientConfig;
import io.quarkus.amazon.common.runtime.SdkConfig;
import io.quarkus.amazon.common.runtime.SyncHttpClientConfig;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClientBuilder;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
@Recorder
public class DynamodbRecorder {
public RuntimeValue getSyncConfig(DynamodbConfig config) {
return new RuntimeValue<>(config.syncClient);
}
public RuntimeValue getAsyncConfig(DynamodbConfig config) {
return new RuntimeValue<>(config.asyncClient);
}
public RuntimeValue getAwsConfig(DynamodbConfig config) {
return new RuntimeValue<>(config.aws);
}
public RuntimeValue getSdkConfig(DynamodbConfig config) {
return new RuntimeValue<>(config.sdk);
}
public RuntimeValue createSyncBuilder(DynamodbConfig config,
RuntimeValue transport) {
DynamoDbClientBuilder builder = DynamoDbClient.builder();
builder.endpointDiscoveryEnabled(config.enableEndpointDiscovery);
if (transport != null) {
builder.httpClientBuilder(transport.getValue());
}
return new RuntimeValue<>(builder);
}
public RuntimeValue createAsyncBuilder(DynamodbConfig config,
RuntimeValue transport) {
DynamoDbAsyncClientBuilder builder = DynamoDbAsyncClient.builder();
builder.endpointDiscoveryEnabled(config.enableEndpointDiscovery);
if (transport != null) {
builder.httpClientBuilder(transport.getValue());
}
return new RuntimeValue<>(builder);
}
public RuntimeValue buildClient(RuntimeValue extends AwsClientBuilder> builder,
BeanContainer beanContainer,
ShutdownContext shutdown) {
DynamodbClientProducer producer = beanContainer.instance(DynamodbClientProducer.class);
producer.setSyncConfiguredBuilder((DynamoDbClientBuilder) builder.getValue());
shutdown.addShutdownTask(producer::destroy);
return new RuntimeValue<>(producer.client());
}
public RuntimeValue buildAsyncClient(RuntimeValue extends AwsClientBuilder> builder,
BeanContainer beanContainer,
ShutdownContext shutdown) {
DynamodbClientProducer producer = beanContainer.instance(DynamodbClientProducer.class);
producer.setAsyncConfiguredBuilder((DynamoDbAsyncClientBuilder) builder.getValue());
shutdown.addShutdownTask(producer::destroy);
return new RuntimeValue<>(producer.asyncClient());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy