【问题标题】:Not able to uploading csv file to azure storage blob无法将 csv 文件上传到 Azure 存储 Blob
【发布时间】:2021-10-01 02:45:58
【问题描述】:

以下代码不会将示例 MY_TEST_FILE.csv 上传到 Azure 存储 Blob。无法解决问题或找到任何这样做的示例。代码中缺少什么?日志中没有错误,在 Azure 存储中找不到文件

'''

        StorageSharedKeyCredential credential = new StorageSharedKeyCredential("test", "test");
        String uri = "https://test.blob.core.windows.net";

        BlobServiceClient client = new BlobServiceClientBuilder()
                .endpoint(uri)
                .credential(credential)
                .buildClient();
        CamelContext mycontext = new DefaultCamelContext();
        mycontext.getRegistry().bind("client", client);
       
        mycontext.setStreamCaching(true);
        mycontext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() {
              

                from("file:c://folder2?fileName=MY_TEST_FILE.csv&noop=true").to("azure-storage-blob://test/report?blobName=MY_TEST_FILE.csv&operation=uploadBlockBlob&serviceClient=#client");


            }
        });
        mycontext.start();'''

【问题讨论】:

    标签: spring-boot apache-camel azure-blob-storage


    【解决方案1】:

    您可能需要为 azure-storage-blob 组件提供凭据。

    StorageSharedKeyCredential credentials = new StorageSharedKeyCredential(accountName, accountKey);
    mycontext.getRegistry().bind("credentials", credentials);
    
    from("file:c://folder2?fileName=MY_TEST_FILE.csv&noop=true")
        .to("azure-storage-blob:accountName/containerName?"
             + "blobName=MY_TEST_FILE.csv&operation=uploadBlockBlob"
             + "&credentials=#credentials");
    

    请注意,#beanIddeprecated,您可能需要切换到 #bean:beanId,具体取决于骆驼版本。

    【讨论】:

    • 还是不行。我可以在日志文件中看到以下错误 java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
    • 你用的是什么版本的骆驼?较旧的骆驼版本使用 Azure SDK 版本 8,而较新的骆驼版本使用 SDK 12,这可能会导致一些差异。您也可以尝试不使用 serviceClient 进行定义,我猜它用于更多 advanced 配置。
    • 另外,最好将日志等新信息添加到原始问题中,而不是将它们塞进 cmets。
    • 在 spring 应用程序中运行相同的代码后问题得到了修复。运行独立类导致问题
    • 是的,对于独立的camel应用程序,通常建议使用camel主类或spring之类的框架。有很多 maven 原型可以让它们很容易设置。
    猜你喜欢
    • 2020-07-13
    • 1970-01-01
    • 2019-12-01
    • 2017-01-24
    • 2017-08-19
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    相关资源
    最近更新 更多