【问题标题】:Camel-Azure BlobServiceProducer IllegalArgumentException: Unsupported blob type:org.apache.camel.component.file.GenericFileCamel-Azure BlobServiceProducer IllegalArgumentException:不支持的 blob 类型:org.apache.camel.component.file.GenericFile
【发布时间】:2020-12-29 07:17:37
【问题描述】:

我编写了一个骆驼路由,它轮询文件夹并将其发送到 Azure Blob 容器

我按照 Azure 文档页面中提到的示例进行操作 https://github.com/apache/camel/blob/master/components/camel-azure/src/main/docs/azure-blob-component.adoc

我正在反转路线。我使用的是 Azure Blob 生产者,而不是消费者。 这是我的路线。我使用过 Java DSL。

from("file://C:/camel/source1").to("azure-blob://datastorage/container1/BLOB1?credentials=#credentials&operation=updateBlockBlob")

当我放置文件时,出现以下错误。

**java.lang.IllegalArgumentException: Unsupported blob type:org.apache.camel.component.file.GenericFile
    at org.apache.camel.component.azure.blob.BlobServiceProducer.getInputStreamFromExchange(BlobServiceProducer.java:474) ~[camel-azure-2.19.2.jar:2.19.2]
    at org.apache.camel.component.azure.blob.BlobServiceProducer.updateBlockBlob(BlobServiceProducer.java:143) ~[camel-azure-2.19.2.jar:2.19.2]
    at org.apache.camel.component.azure.blob.BlobServiceProducer.process(BlobServiceProducer.java:79) ~[camel-azure-2.19.2.jar:2.19.2]**

我能够解决这个问题。我将路线改写为。

    from("file://C:/camel/source1")
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    Object file = exchange.getIn().getMandatoryBody();

                    exchange.getOut().setBody(
                            GenericFileConverter.genericFileToInputStream(
                                    (GenericFile<?>) file, exchange));
                }
            })
            .to("azure-blob://datastorage/container1/BLOB1?credentials=#credentials&operation=updateBlockBlob")
            .to("mock:Result");

我的问题是,我真的需要编写处理器吗?骆驼组件不应该接收流或文件对象吗?

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    是的,这是一个小错误。我已经签了一张票:https://issues.apache.org/jira/browse/CAMEL-11844

    您可以执行您所做的解决方法,或者您可以添加一个 .convertBodyTo 并转换为 FileInputStream、String 等。

     from("file://C:/camel/source1")
         .convertBodyTo(String.class)
         ...
    

    【讨论】:

    • 有没有办法通过拦截器做到这一点?我试过了,但我有多个路线,我列出 blob 并更新 blob。仅当它是 azure-blob 并且 operation=update 时才想做。猜猜可能需要使用一些正则表达式来做到这一点
    • 您可以使用interceptSendToEndpoint("azure*") 然后添加covertBodyTo。查看更多详情:camel.apache.org/intercept
    • 这会导致任何性能问题吗?因为我需要将它发送到天蓝色,所以我认为使用分离器不会有帮助。对不起,我跑题了
    • interceptSendToEndpoint 不会导致性能问题,它会在 Camel 构建路由并将 .convertBodyTo 添加为内联时进行拦截,就好像您自己输入了一样。但是对于任何与性能相关的事情,请询问计算机 - 例如,自己进行测试和比较。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-13
    相关资源
    最近更新 更多