无法通过Apache camel检索MinIO对象

gev0vcfq  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(188)

我在通过Apache Camel从MinIO服务器检索对象时遇到问题。
我正在使用一个“第三方”库(我不能直接更改它),它使用以下方法连接到camel并下载对象:

ConsumerTemplate template = context.createConsumerTemplate();
byte[] content = template.receiveBody(uri, timeout, byte[].class);

我将我的MinIO的“ Camel 味”URI传递给这段代码,格式如下:

String camelUri = "minio://myBucketName?prefix=hello.txt");

我正在为MinIO配置Apache Camel组件,如下所示:

@Bean
    public MinioClient minioClient() {
        return new MinioClient.Builder()
                .credentials(accessKey, secretKey)
                .endpoint(url)
                .build();
    }

@Bean
public CamelContext camelContext(MinioClient client) {
    CamelContext context = new DefaultCamelContext();
    context.setTracing(true);
    context.start();

    MinioComponentBuilder minioCompBuilder = 
    ComponentsBuilderFactory.minio().minioClient(client).secure(true);
    minioCompBuilder.register(context, "minio");
    return context;
}

通过启用TRACE级别,我可以看到camel能够建立连接,首先验证bucket是否已经存在,但是没有返回任何内容。
以下配置选项将作为查询字符串传递,我也尝试了该选项:

String camelUri = "minio://myBucketName?objectName=hello.txt;

仍然没有返回任何内容。
在日志中:

"message":"Starting service: minio://myBucketName?prefix=hello.txt&startScheduler=false"    "message":"Querying whether bucket myBucketName already exists..."  "message":"Bucket myBucketName already exists"  "message":"Started service: minio://myBucketName?prefix=hello.txt&startScheduler=false"     "message":"<<<< minio://myBucketName?prefix=hello.txt&startScheduler=false"     "message":"Creating service from endpoint: minio://myBucketName?prefix=hello.txt&startScheduler=false"  "message":"Creating EventDrivenPollingConsumer with queueSize: 1000 blockWhenFull: true blockTimeout: 0 copy: false"    "message":"Building service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Built service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Initializing service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Building service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Build consumer: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Building service: org.apache.camel.impl.engine.PrototypeExchangeFactory@427e563c"
"message":"Warming up PrototypeExchangeFactory loaded class: org.apache.camel.support.DefaultExchange"
"message":"Built service: org.apache.camel.impl.engine.PrototypeExchangeFactory@427e563c"
"message":"Warming up DefaultConsumer loaded class: org.apache.camel.support.DefaultConsumer$DefaultConsumerCallback"
"message":"Built service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Initializing service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Init consumer: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Initializing service: org.apache.camel.impl.engine.PrototypeExchangeFactory@427e563c"
"message":"Initialized service: org.apache.camel.impl.engine.PrototypeExchangeFactory@427e563c"
"message":"Initialized service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Initialized service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Starting service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Started service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Acquired service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Before poll minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Starting service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Starting consumer: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Starting service: org.apache.camel.impl.engine.PrototypeExchangeFactory@427e563c"
"message":"Started service: org.apache.camel.impl.engine.PrototypeExchangeFactory@427e563c"
"message":"Service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false already started"
"message":"Building service: org.apache.camel.support.DefaultScheduledPollConsumerScheduler@1c0e57e4"
"message":"Built service: org.apache.camel.support.DefaultScheduledPollConsumerScheduler@1c0e57e4"
"message":"Initializing service: org.apache.camel.support.DefaultScheduledPollConsumerScheduler@1c0e57e4"
"message":"Initialized service: org.apache.camel.support.DefaultScheduledPollConsumerScheduler@1c0e57e4"
"message":"Starting service: org.apache.camel.support.DefaultScheduledPollConsumerScheduler@1c0e57e4"
"message":"Created new ScheduledThreadPool for source: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false] with name: minio://myBucketName?prefix=hello.txt&startScheduler=false -> org.apache.camel.util.concurrent.SizedScheduledExecutorService@1eef6e57[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Started service: org.apache.camel.support.DefaultScheduledPollConsumerScheduler@1c0e57e4"
"message":"Scheduling 1 consumers poll (fixed delay) with initialDelay: 1000, delay: 500 (milliseconds) for: minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"canScheduleOrExecute 0 < 1000 -> true"
"message":"Created thread[Camel (camel-1) thread #1 - minio://myBucketName] -> Thread[Camel (camel-1) thread #1 - minio://myBucketName,5,main]"
"message":"Started service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"After poll minio://myBucketName?prefix=hello.txt&startScheduler=false"
"message":"Suspending service MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Suspending service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Suspended service: MinioConsumer[minio://myBucketName?prefix=hello.txt&startScheduler=false]"
"message":"Released service: PollingConsumer on minio://myBucketName?prefix=hello.txt&startScheduler=false"
,"message":"Scheduled task started on:   minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Cannot start to poll: minio://myBucketName?prefix=hello.txt&startScheduler=false as its suspended"}
,"message":"Scheduled task completed on: minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Scheduled task started on:   minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Cannot start to poll: minio://myBucketName?prefix=hello.txt&startScheduler=false as its suspended"}
,"message":"Scheduled task completed on: minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Scheduled task started on:   minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Cannot start to poll: minio://myBucketName?prefix=hello.txt&startScheduler=false as its suspended"}
,"message":"Scheduled task completed on: minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Scheduled task started on:   minio://myBucketName?prefix=hello.txt&startScheduler=false"}
,"message":"Cannot start to poll: minio://myBucketName?prefix=hello.txt&startScheduler=false as its suspended"}
..... and goes on with this util i stop the application.

我是camel的新手,我不明白为什么它也会创建一个PollingConsumer和调度器(我确实尝试过阻止传递 startScheduler=false),并且轮询之后不断尝试启动,但失败了。可能这应该以另一个问题结束,我认为这与我的问题无关。
我的相依性:

<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-minio</artifactId>
        <version>3.14.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-componentdsl</artifactId>
        <version>3.14.4</version>
    </dependency>
    <dependency>
        <groupId>io.minio</groupId>
        <artifactId>minio</artifactId>
        <version>8.4.1</version>
    </dependency>

在MinIo服务器中,该文件位于Bucket的正下方:我的存储桶名称/hello.txt
此外,我还使用MinioClient(注入MinioComponentBuilder的相同内容)进行了直接调用测试:

GetObjectResponse getObj =  minioClient.getObject(GetObjectArgs.builder()
                    .bucket("myBucketName")
                    .object("hello.txt").build());
 String input = new String(getObj.readAllBytes());
 log.info("TXT CONTENT: {}",input);

而且它工作得很好,打印了txt的内容。
我可能在uri语法和我如何编写它方面做了一些错误的事情,但无法弄清楚。

at0kjp5o

at0kjp5o1#

我和Stefano一起工作,这个问题和minio组件的camel实现有关。解决方案如下。recevivedBody是一个重载方法的接口,如果需要超时,请将最小超时设置为1100米利斯,否则结果将为空,如果不需要,请使用没有超时的方法。
有超时

ConsumerTemplate template = context.createConsumerTemplate();
byte[] content = template.receiveBody(uri, 1100, byte[].class);

无超时

ConsumerTemplate template = context.createConsumerTemplate();
byte[] content = template.receiveBody(uri, byte[].class);

相关问题