使用Apache Camel列出来自Springboot的AWS S3存储桶内容

pgky5nke  于 2022-11-07  发布在  Apache
关注(0)|答案(2)|浏览(173)

我有一个运行v2.5.4的sprintboot项目,它运行得很好。我可以访问S3,并且我可以列出我创建的一个bucket的内容。所以我想用Apache Camel进行试验,尝试只列出一个bucket的内容,根据示例,这应该是非常简单的。但是我一直收到错误。
我在我的build中添加了2个依赖项。gradle

implementation group: 'org.apache.camel.springboot', name: 'camel-core-starter', version: '3.13.0'
implementation group: 'org.apache.camel.springboot', name: 'camel-aws2-s3-starter', version: '3.13.0'

然后我就创建了一个SimpleRouteBuilder.java

@Component

公共类SimpleRouteBuilder扩展了路由构建器{

@Override
public void configure() throws Exception {
    from("aws2-s3://bucketName?amazonS3Client=#createS3Client&operation=listObjects&accessKey=xxxAccessKeyxxx&secretKey=xxxSecretKeyxxx")
            .log("Received body: ");
}

我一直收到这个堆栈跟踪
在我的aws 3客户机工厂上,我已经设置了bean名称。

@Slf4j
@Configuration
public class S3ClientBeanFactory {

    @Bean(name = "s3Client")

这看起来很有效--当我把名字改成其他名字时,我得到一个错误:

No bean could be found in the registry for:S3Client

但是在camel端点url中设置了“s3 client”之后,我总是会遇到这种情况。

2021-12-13 12:23:25.036  INFO [,,] 28267 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.13.0 (camel-1) shutdown in 4ms (uptime:511ms)
2021-12-13 12:23:25.045  INFO [,,] 28267 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-12-13 12:23:25.069  INFO [,,] 28267 --- [           main] ConditionEvaluationReportLoggingListener : 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-13 12:23:25.085 ERROR [,,] 28267 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.apache.camel.FailedToStartRouteException: Failed to start route route1 because of null
2021-12-13 12:23:25.036  INFO [,,] 28267 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.13.0 (camel-1) shutdown in 4ms (uptime:511ms)
2021-12-13 12:23:25.045  INFO [,,] 28267 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-12-13 12:23:25.069  INFO [,,] 28267 --- [           main] ConditionEvaluationReportLoggingListener : 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-13 12:23:25.085 ERROR [,,] 28267 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.apache.camel.FailedToStartRouteException: Failed to start route route1 because of null
    at org.apache.camel.impl.engine.RouteService.warmUp(RouteService.java:123)
    at org.apache.camel.impl.engine.InternalRouteStartupManager.doWarmUpRoutes(InternalRouteStartupManager.java:306)
    at org.apache.camel.impl.engine.InternalRouteStartupManager.safelyStartRouteServices(InternalRouteStartupManager.java:189)
    at org.apache.camel.impl.engine.InternalRouteStartupManager.doStartOrResumeRoutes(InternalRouteStartupManager.java:147)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:3201)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStartContext(AbstractCamelContext.java:2863)
    at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2814)
    at org.apache.camel.spring.boot.SpringBootCamelContext.doStart(SpringBootCamelContext.java:43)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:119)
    at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2510)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:246)
    at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:119)
    at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:151)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
    at dk.danskespil.scratchgames.ScratchgamesApplication.main(ScratchgamesApplication.java:22)
Caused by: software.amazon.awssdk.services.s3.model.S3Exception: null (Service: S3, Status Code: 403, Request ID: null, Extended Request ID: FknaUW6/yRkYvJry9d8oIWU2hC4aRk7z8ilAZZxlcDN4s+P4bAoyzWVriJxUYj2bCyzCFFMSGNY=)

这个操作是不可能的还是我做这么简单的操作缺少了什么?

1wnzp6jl

1wnzp6jl1#

我在使用Apache Camel组件 * aws 2-s3://* 时遇到了同样的问题,这是由AWS S3上的权限不足引起的:

Caused by: software.amazon.awssdk.services.s3.model.S3Exception: null (Service: S3, Status Code: 403, ...)

但我必须提到的是,来自Amazon SDK的S3 Client工作得很好用于阅读具有相同权限=相同帐户的文件。
说明:我发现此 * aws 2-s3://* 组件需要进行 headBucket API调用(和其他),这会导致错误,因为进行此API调用的权限不足。

3mpgtkmj

3mpgtkmj2#

Spring并不认为配置bean是特殊的,路由bean有可能在S3客户端bean之前创建。
我会尝试在route bean上使用@DependsOn({"s3ClientBeanFactory"})-注解。Controlling Bean Creation Order with @DependsOn Annotation

相关问题