6.13. 创建 S3 客户端并在 registry 中添加组件
有时,您要使用 AWS2S3Configuration 执行一些高级配置,这还允许设置 S3 客户端。您可以在组件配置中创建和设置 S3 客户端,如下例所示
String awsBucketAccessKey = "your_access_key";
String awsBucketSecretKey = "your_secret_key";
S3Client s3Client = S3Client.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(awsBucketAccessKey, awsBucketSecretKey)))
.region(Region.US_EAST_1).build();
AWS2S3Configuration configuration = new AWS2S3Configuration();
configuration.setAmazonS3Client(s3Client);
configuration.setAutoDiscoverClient(true);
configuration.setBucketName("s3bucket2020");
configuration.setRegion("us-east-1");
现在,您可以配置 S3 组件(使用上面创建的配置对象),并在路由初始化前将其添加到配置方法中的 registry 中。
AWS2S3Component s3Component = new AWS2S3Component(getContext());
s3Component.setConfiguration(configuration);
s3Component.setLazyStartProducer(true);
camelContext.addComponent("aws2-s3", s3Component);
现在,您的组件将用于在 camel 路由中实施的所有操作。