2017-06-19 27 views
1

我有一條路線如下。它適用於小文件,但對於大文件(大約6GB或更多),我的程序耗盡內存。如何在不存儲內容的情況下對內容進行流式傳輸?Apache Camel:如何從AWS流式傳輸大文件?

public void configure() throws Exception { 
    S3LastModifiedFilter lastModifiedFilter = 
      new S3LastModifiedFilter(s3Properties.getLastModifiedWithinSeconds(), s3Properties.getPrefix()); 

    from(inboundS3Uri) 
      .filter().method(lastModifiedFilter, "accept") 
      .idempotentConsumer(header(S3Constants.KEY), 
        MemoryIdempotentRepository.memoryIdempotentRepository(inboundCacheSize)) 
      .convertBodyTo(byte[].class, UTF_8.name()) 
      .process(new ForHttpMessageProcessor(httpProperties)) 
      .to(outboundHttpUri); 
} 

錯誤

Caused by: org.apache.camel.TypeConversionException: Error during type conversion from type: java.lang.String to the required type: byte[] with value [Body is instance of java.io.InputStream] due java.lang.OutOfMemoryError: Java heap space 
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.createTypeConversionException(BaseTypeConverterRegistry.java:629) 
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:190) 
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:108) 
    ... 23 common frames omitted 
Caused by: org.apache.camel.RuntimeCamelException: java.lang.OutOfMemoryError: Java heap space 
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1774) 

回答

1

原來的線convertBodyTo(byte[].class, UTF_8.name())是問題。它試圖緩衝內存中的內容並將其轉換爲字符串。我評論說,現在的代碼工作。