2017-06-19 2 views
1

Ich habe eine Route wie folgt. Es funktioniert für kleine Dateien, aber für große (etwa 6 GB oder mehr) hat mein Programm nicht genügend Arbeitsspeicher. Wie streame ich den Inhalt ohne Speicherung im Speicher?Apache Camel: Wie große Dateien von AWS zu streamen?

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); 
} 

Fehler:

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) 

Antwort

1

Schaltet die Linie convertBodyTo(byte[].class, UTF_8.name()) das Problem war, heraus. Es wurde versucht, den Inhalt im Speicher zu puffern und in eine Zeichenfolge zu konvertieren. Ich habe es auskommentiert, und jetzt funktioniert der Code.