1

我试图在我的 application.properties 文件中设置一个文件名。当我使用此处解释的文件组件时,它运行良好:Smallrye doc

请注意,我在 quarkus 上下文中,所以我必须按照文档中的说明将 $ 加倍。

但是,我不需要写入文件,而是写入 azure blob。事情变得更加复杂。

这是我的配置: mp.messaging.outgoing.water.endpoint-uri=azure-blob://xxxxxx/xxxxx/xxxx/xxxxx-${date:now:ddMMyyyy-hh:mm:ss}.json?credentials=#credentials&operation=updateBlockBlob

如果我加倍 $ 我得到以下堆栈跟踪:

2020-06-26 19:21:02,204 WARN  [org.apa.cam.com.rea.str.ReactiveStreamsConsumer] (Camel (camel-1) thread #0 - reactive-streams://87687045129B977-0000000000000000) Error processing exchange. Exchange[8768704512
9B977-0000000000000001]. Caused by: [java.lang.IllegalArgumentException - Illegal character in path at index 86: https://zstalrsdsmdatarec01.blob.core.windows.net/materiel/MTD-niveaudeau/niveaudeau-${date:now
:ddMMyyyy-hh:mm:ss}.json]: java.lang.IllegalArgumentException: Illegal character in path at index 86: https://zstalrsdsmdatarec01.blob.core.windows.net/materiel/MTD-niveaudeau/niveaudeau-${date:now:ddMMyyyy-h
h:mm:ss}.json                                                                                                                                                                                                   
        at java.net.URI.create(URI.java:852)                                                                                                                                                                    
        at org.apache.camel.component.azure.blob.BlobServiceUtil.prepareStorageBlobUri(BlobServiceUtil.java:214)                                                                                                
        at org.apache.camel.component.azure.blob.BlobServiceUtil.prepareStorageBlobUri(BlobServiceUtil.java:196)                                                                                                
        at org.apache.camel.component.azure.blob.BlobServiceUtil.createBlockBlobClient(BlobServiceUtil.java:135)                                                                                                
        at org.apache.camel.component.azure.blob.BlobServiceProducer.updateBlockBlob(BlobServiceProducer.java:140)                                                                                              
        at org.apache.camel.component.azure.blob.BlobServiceProducer.process(BlobServiceProducer.java:80)                                                                                                       
        at org.apache.camel.support.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:67)                                                                
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:174)                                                                                                                             
        at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:396)                                                                                       
        at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:153)                                                                                               
        at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60)                                                                                                   
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:147)                                                                                                                                       
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:286)                                                                                                           
        at org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer.lambda$doSend$3(ReactiveStreamsConsumer.java:100)                                                                                
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)                                                                                                                      
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)                                                                                                                      
        at java.lang.Thread.run(Thread.java:748)                                                                                                                                                                
Caused by: java.net.URISyntaxException: Illegal character in path at index 86: https://zstalrsdsmdatarec01.blob.core.windows.net/materiel/MTD-niveaudeau/niveaudeau-${date:now:ddMMyyyy-hh:mm:ss}.json          
        at java.net.URI$Parser.fail(URI.java:2848)                                                                                                                                                              
        at java.net.URI$Parser.checkChars(URI.java:3021)                                                                                                                                                        
        at java.net.URI$Parser.parseHierarchical(URI.java:3105)                                                                                                                                                 
        at java.net.URI$Parser.parse(URI.java:3053)                                                                                                                                                             
        at java.net.URI.<init>(URI.java:588)                                                                                                                                                                    
        at java.net.URI.create(URI.java:850)                                                                                                                                                                    
        ... 16 more                                                                                                                                                                                             

所以我尽量不加倍$。我没有任何错误,但在这种情况下,文件名在 azure 中如下所示: MTD-niveaudeau/niveaudeau-now:ddMMyyyy-hh:mm:ss.json

我也尝试使用$simple{ }占位符但没有成功。

我真的很想使用 @Outgoing 注释而不是这样写:

@Incoming( "xxxxxxxx" )
    public void consume( final String message){

        log.info( "Incoming message : {}", message );

        final String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMyyyy-HH:mm:ss"));

        Multi
                .createFrom()
                .completionStage( camel
                        .createProducerTemplate()
                        .asyncSendBody(
                                "azure-blob://xxxxxxx/xxxxx/xxxxxx/xxxxx-"+now+".json?credentials=#credentials&operation=updateBlockBlob"
                                , message.toString() )
                )
                .subscribe()
                .with( e ->
                        log.info( "Message successfullt sent to azure" )
                )
        ;
    }

怎么做 ?

谢谢!

4

0 回答 0