使用azure-blob组件在Apache骆驼中获取“无效的客户端URI”

时间:2019-11-06 15:21:18

标签: azure apache-camel cloud jndi azure-blob-storage

我正在尝试使用azure-blob从云下载或获取blob文件。 到目前为止,路由已成功启动,但预期的blob文件未下载,java程序也立即终止。请建议如何使用 azure-blob 获取所需的Blob文件。

下面是使用azure-blob从云中获取blob数据的代码

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import com.microsoft.azure.storage.StorageCredentials;
import com.microsoft.azure.storage.StorageCredentialsAccountAndKey;
import com.microsoft.azure.storage.StorageUri;
import com.microsoft.azure.storage.blob.CloudBlockBlob;

public class RouteComposer {
    public static void main(String[] args) {
        try {
            StorageCredentials credentials = new StorageCredentialsAccountAndKey("abcdefgh", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            StorageUri storageURI = new StorageUri(new java.net.URI("https://abcdefgh.blob.core.windows.net/abcdefgh"));
            CloudBlockBlob client = new CloudBlockBlob(storageURI, credentials);
            org.apache.camel.impl.JndiRegistry registry = new org.apache.camel.impl.JndiRegistry();
            System.setProperty("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory");
            registry.bind("clientreg", client);
            CamelContext mycontext = new DefaultCamelContext(registry);
            mycontext.setStreamCaching(true);
            mycontext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                    from("azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=#clientreg&operation=getBlob")
                    .routeId("SampleRoute").to("file:c://output");
                }
            });
            mycontext.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

请在我在Java程序上方运行时找到以下日志

19:21:19.409 [Camel Thread #0 - LRUCacheFactory] DEBUG org.apache.camel.util.LRUCacheFactory - Warming up LRUCache ...
19:21:19.500 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Adding routes from builder: Routes: []
19:21:19.752 [Camel Thread #0 - LRUCacheFactory] DEBUG org.apache.camel.util.LRUCacheFactory - Warming up LRUCache complete in 343 millis
19:21:19.906 [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.0.fuse-740039-redhat-00001 (CamelContext: camel-1) is starting
19:21:19.906 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Using ClassResolver=org.apache.camel.impl.DefaultClassResolver@7a187f14, PackageScanClassResolver=org.apache.camel.impl.DefaultPackageScanClassResolver@6f195bc3, ApplicationContextClassLoader=null, RouteController=org.apache.camel.impl.DefaultRouteController@51e2adc7
19:21:19.906 [main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is enabled on CamelContext: camel-1
19:21:19.906 [main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled
19:21:20.045 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Starting JMX agent on server: com.sun.jmx.mbeanserver.JmxMBeanServer@2c039ac6
19:21:20.239 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=context,name="camel-1"
19:21:20.239 [main] DEBUG org.apache.camel.support.TimerListenerManager - Added TimerListener: org.apache.camel.management.mbean.ManagedCamelContext@6ee12bac
19:21:20.239 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=health,name="camel-1"
19:21:20.249 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=routecontrollers,name="camel-1"
19:21:20.338 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultTypeConverter
19:21:20.350 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Found 3 packages with 19 @Converter classes to load
19:21:20.461 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Loading file META-INF/services/org/apache/camel/TypeConverter to retrieve list of packages, from url: jar:file:/C:/Users/schintha/.m2/repository/org/apache/camel/camel-core/2.21.0.fuse-740039-redhat-00001/camel-core-2.21.0.fuse-740039-redhat-00001.jar!/META-INF/services/org/apache/camel/TypeConverter
19:21:20.471 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Loading file META-INF/services/org/apache/camel/TypeConverter to retrieve list of packages, from url: jar:file:/C:/Users/schintha/.m2/repository/org/apache/camel/camel-spring/2.21.0.fuse-740039-redhat-00001/camel-spring-2.21.0.fuse-740039-redhat-00001.jar!/META-INF/services/org/apache/camel/TypeConverter
19:21:20.471 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Loading file META-INF/services/org/apache/camel/TypeConverter to retrieve list of packages, from url: jar:file:/C:/Users/schintha/.m2/repository/org/apache/camel/camel-netty4/2.21.0.fuse-740039-redhat-00001/camel-netty4-2.21.0.fuse-740039-redhat-00001.jar!/META-INF/services/org/apache/camel/TypeConverter
19:21:20.471 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Loading file META-INF/services/org/apache/camel/TypeConverter to retrieve list of packages, from url: jar:file:/C:/Users/schintha/.m2/repository/org/apache/camel/camel-netty4-http/2.21.0.fuse-740039-redhat-00001/camel-netty4-http-2.21.0.fuse-740039-redhat-00001.jar!/META-INF/services/org/apache/camel/TypeConverter
19:21:20.471 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Loading file META-INF/services/org/apache/camel/TypeConverter to retrieve list of packages, from url: jar:file:/C:/Users/schintha/.m2/repository/org/apache/camel/camel-http-common/2.21.0.fuse-740039-redhat-00001/camel-http-common-2.21.0.fuse-740039-redhat-00001.jar!/META-INF/services/org/apache/camel/TypeConverter
19:21:20.481 [main] DEBUG org.apache.camel.impl.converter.AnnotationTypeConverterLoader - Loaded 4 @Converter classes
19:21:20.504 [main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Type converters loaded (core: 194, classpath: 21)
19:21:20.504 [main] DEBUG org.apache.camel.util.ResolverHelper - Lookup Language with name simple in registry. Found: null
19:21:20.504 [main] DEBUG org.apache.camel.util.ResolverHelper - Lookup Language with name simple-language in registry. Found: null
19:21:20.534 [main] DEBUG org.apache.camel.language.simple.SimpleLanguage - Simple language predicate/expression cache size: 1000
19:21:20.554 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultEndpointRegistry
19:21:20.574 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultExecutorServiceManager
19:21:20.574 [main] DEBUG org.apache.camel.impl.SharedProducerServicePool - Starting service pool: org.apache.camel.impl.SharedProducerServicePool@2a798d51
19:21:20.574 [main] DEBUG org.apache.camel.impl.SharedPollingConsumerServicePool - Starting service pool: org.apache.camel.impl.SharedPollingConsumerServicePool@6d763516
19:21:20.584 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultInflightRepository
19:21:20.594 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultAsyncProcessorAwaitManager
19:21:20.594 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultShutdownStrategy
19:21:20.604 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultRestRegistry
19:21:20.625 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultRuntimeCamelCatalog
19:21:20.635 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultTransformerRegistry
19:21:20.653 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultValidatorRegistry
19:21:20.676 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Using ComponentResolver: org.apache.camel.impl.DefaultComponentResolver@33d512c1 to resolve component with name: azure-blob
19:21:20.676 [main] DEBUG org.apache.camel.util.ResolverHelper - Lookup Component with name azure-blob in registry. Found: null
19:21:20.676 [main] DEBUG org.apache.camel.util.ResolverHelper - Lookup Component with name azure-blob-component in registry. Found: null
19:21:20.676 [main] DEBUG org.apache.camel.impl.DefaultComponentResolver - Found component: azure-blob via type: org.apache.camel.component.azure.blob.BlobServiceComponent via: META-INF/services/org/apache/camel/component/azure-blob
19:21:20.716 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=components,name="azure-blob"
19:21:20.716 [main] DEBUG org.apache.camel.impl.DefaultComponent - Cannot resolve property placeholders on component: org.apache.camel.component.azure.blob.BlobServiceComponent@6025e1b6 as PropertiesComponent is not in use
19:21:20.744 [main] DEBUG org.apache.camel.impl.DefaultComponent - Creating endpoint uri=[azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob], path=[abcdefgh/abcdefgh/test.rpm]
19:21:20.757 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob converted to endpoint: azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob by component: org.apache.camel.component.azure.blob.BlobServiceComponent@6025e1b6
19:21:20.797 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=endpoints,name="azure-blob://abcdefgh/abcdefgh/test.rpm\?azureBlobClient=%23clientreg&operation=getBlob"
19:21:20.827 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Using ComponentResolver: org.apache.camel.impl.DefaultComponentResolver@33d512c1 to resolve component with name: file
19:21:20.827 [main] DEBUG org.apache.camel.util.ResolverHelper - Lookup Component with name file in registry. Found: null
19:21:20.827 [main] DEBUG org.apache.camel.util.ResolverHelper - Lookup Component with name file-component in registry. Found: null
19:21:20.857 [main] DEBUG org.apache.camel.impl.DefaultComponentResolver - Found component: file via type: org.apache.camel.component.file.FileComponent via: META-INF/services/org/apache/camel/component/file
19:21:20.878 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=components,name="file"
19:21:20.878 [main] DEBUG org.apache.camel.impl.DefaultComponent - Cannot resolve property placeholders on component: org.apache.camel.component.file.FileComponent@7c9d8e2 as PropertiesComponent is not in use
19:21:20.889 [main] DEBUG org.apache.camel.impl.DefaultComponent - Creating endpoint uri=[file://c://output], path=[c://output]
19:21:20.899 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - file://c://output converted to endpoint: file://c://output by component: org.apache.camel.component.file.FileComponent@7c9d8e2
19:21:20.929 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=endpoints,name="file://c://output"
19:21:20.949 [main] DEBUG org.apache.camel.processor.interceptor.DefaultChannel - Initialize channel for target: 'To[file:c://output]'
19:21:20.959 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer
19:21:20.980 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=tracer,name=BacklogDebugger
19:21:21.020 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=errorhandlers,name="DefaultErrorHandlerBuilder(ref:CamelDefaultErrorHandlerBuilder)"
19:21:21.040 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=services,name=DefaultStreamCachingStrategy
19:21:21.211 [main] DEBUG org.apache.camel.impl.DefaultStreamCachingStrategy - Created spool directory: C:\Users\schintha\AppData\Local\Temp\camel\camel-tmp-fda3bb35-6967-4d27-818b-522670a70433
19:21:21.211 [main] DEBUG org.apache.camel.impl.DefaultStreamCachingStrategy - StreamCaching configuration DefaultStreamCachingStrategy[spoolDirectory=C:\Users\schintha\AppData\Local\Temp\camel\camel-tmp-fda3bb35-6967-4d27-818b-522670a70433, spoolChiper=null, spoolThreshold=131072, spoolUsedHeapMemoryThreshold=0, bufferSize=4096, anySpoolRules=false]
19:21:21.211 [main] INFO org.apache.camel.impl.DefaultStreamCachingStrategy - StreamCaching in use with spool directory: C:\Users\schintha\AppData\Local\Temp\camel\camel-tmp-fda3bb35-6967-4d27-818b-522670a70433 and rules: [Spool > 128K body size]
19:21:21.211 [main] DEBUG org.apache.camel.impl.HeadersMapFactoryResolver - Creating default HeadersMapFactory
19:21:21.211 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Using HeadersMapFactory: org.apache.camel.impl.DefaultHeadersMapFactory@6b8ca3c8
19:21:21.211 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Warming up route id: SampleRoute having autoStartup=true
19:21:21.211 [main] DEBUG org.apache.camel.impl.RouteService - Starting services on route: SampleRoute
19:21:21.222 [main] DEBUG org.apache.camel.impl.RouteService - Starting child service on route: SampleRoute -> Channel[sendTo(file://c://output)]
19:21:21.242 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=producers,name=GenericFileProducer(0x53976f5c)
19:21:21.242 [main] DEBUG org.apache.camel.impl.ProducerCache - Adding to producer cache with key: file://c://output for producer: Producer[file://c://output]
19:21:21.242 [main] DEBUG org.apache.camel.impl.RouteService - Starting child service on route: SampleRoute -> sendTo(file://c://output)
19:21:21.292 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=processors,name="to1"
19:21:21.292 [main] DEBUG org.apache.camel.impl.RouteService - Starting child service on route: SampleRoute -> Channel[sendTo(file://c://output)]
19:21:21.320 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=routes,name="SampleRoute"
19:21:21.320 [main] DEBUG org.apache.camel.support.TimerListenerManager - Added TimerListener: org.apache.camel.management.mbean.ManagedSuspendableRoute@2e55dd0c
19:21:21.322 [main] DEBUG org.apache.camel.management.DefaultManagementLifecycleStrategy - Load performance statistics disabled
19:21:21.322 [main] DEBUG org.apache.camel.component.file.GenericFileProducer - Starting producer: Producer[file://c://output]
19:21:21.322 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Route: SampleRoute >>> EventDrivenConsumerRoute[azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob -> Channel[sendTo(file://c://output)]]
19:21:21.322 [main] DEBUG org.apache.camel.impl.DefaultCamelContext - Starting consumer (order: 1000) on route: SampleRoute
19:21:21.322 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=consumers,name=BlobServiceConsumer(0x3d1cfad4)
19:21:21.343 [main] DEBUG org.apache.camel.component.azure.blob.BlobServiceConsumer - Starting consumer: Consumer[azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob]
19:21:21.363 [main] DEBUG org.apache.camel.management.DefaultManagementAgent - Registered MBean with ObjectName: org.apache.camel:context=camel-1,type=threadpools,name="BlobServiceConsumer(0x3d1cfad4)"
19:21:21.363 [main] DEBUG org.apache.camel.impl.DefaultExecutorServiceManager - Created new ScheduledThreadPool for source: Consumer[azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob] with name: azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob -> org.apache.camel.util.concurrent.SizedScheduledExecutorService@21282ed8[azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob]
19:21:21.363 [main] DEBUG org.apache.camel.impl.DefaultScheduledPollConsumerScheduler - Scheduling poll (fixed delay) with initialDelay: 1000, delay: 500 (milliseconds) for: azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob
19:21:21.373 [main] INFO org.apache.camel.impl.DefaultCamelContext - Route: SampleRoute started and consuming from: azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&operation=getBlob
19:21:21.373 [main] INFO org.apache.camel.impl.DefaultCamelContext - Total 1 routes, of which 1 are started
19:21:21.373 [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.0.fuse-740039-redhat-00001 (CamelContext: camel-1) started in 1.487 seconds

我遇到错误

19:00:50.189 [Camel (camel-1) thread #1 - azure-blob://abcdefgh/abcdefgh/test.rpm] WARN org.apache.camel.component.azure.blob.BlobServiceConsumer - Consumer Consumer[azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&fileDir=c%3A%2F%2Foutput&operation=getBlob] failed polling endpoint: azure-blob://abcdefgh/abcdefgh/test.rpm?azureBlobClient=%23clientreg&fileDir=c%3A%2F%2Foutput&operation=getBlob. Will try again at next poll. Caused by: [java.lang.IllegalArgumentException - Invalid Client URI]
java.lang.IllegalArgumentException: Invalid Client URI
    at org.apache.camel.component.azure.blob.BlobServiceUtil.getConfiguredClient(BlobServiceUtil.java:179)
    at org.apache.camel.component.azure.blob.BlobServiceUtil.createBlockBlobClient(BlobServiceUtil.java:133)
    at org.apache.camel.component.azure.blob.BlobServiceUtil.getBlockBlob(BlobServiceUtil.java:66)
    at org.apache.camel.component.azure.blob.BlobServiceUtil.getBlob(BlobServiceUtil.java:51)
    at org.apache.camel.component.azure.blob.BlobServiceConsumer.getBlob(BlobServiceConsumer.java:57)
    at org.apache.camel.component.azure.blob.BlobServiceConsumer.poll(BlobServiceConsumer.java:44)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    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)

程序将终止,而不下载blob文件。 请指出我想念的地方和地方 添加JNDI标签以了解是否存在任何JNDI错误

0 个答案:

没有答案