2016-08-04 73 views
0

我爲我的項目的文檔下載/上傳的寧靜服務創建了camel-jetty http代理橋接器。這些服務被調用來獲取/上傳不同類型的文檔,大部分文件大小超過100MB。camel-jetty http代理花費太多時間來處理大量請求流(文件上傳)

當我直接調用上傳剩餘服務(HTTP POST)(不通過camel-jetty http代理進行路由)上傳100MB文檔時,只需要大約2-3分鐘即可完成上傳並接收響應然而,當我通過駱駝路由發送請求時,它需要超過15分鐘,這很奇怪,因爲正在使用的駱駝路由不過是HTTP代理。

以下是一些信息:

駱駝版本2.15.1

駱駝路由定義

<route> 
     <from uri="jetty:http://0.0.0.0:8383/sqidds/document?disableStreamCache=true&amp;matchOnUriPrefix=true&amp;enableMultipartFilter=false&amp;continuationTimeout=-1" /> 
     <log id="incomingMessage" message="incomingMessage - \n[id = ${id}]\n [headers = ${headers}]" /> 
     <to uri="jetty:http://somehost:8080/sqidds/document?bridgeEndpoint=true&amp;throwExceptionOnFailure=false&amp;httpClient.timeout=3200000" /> 
     <log id="outgoingMessage" message="outgoingMessage - \n[id = ${id}]\n [headers = ${headers}]" /> 
    </route> 

駱駝項目POM摘錄:

. 
    . 
    . 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-core</artifactId> 
     <version>2.15.1.redhat-621084</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-spring</artifactId> 
     <version>2.15.1.redhat-621084</version> 
    </dependency> 
    . 
    . 
    . 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-jetty</artifactId> 
     <version>2.15.1.redhat-621084</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.camel</groupId> 
     <artifactId>camel-http</artifactId> 
     <version>2.15.1.redhat-621084</version> 
     <!-- use the same version as your Camel core version --> 
    </dependency> 
    . 
    . 
    . 

REST服務(Spring MVC的)代碼

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) 
public @ResponseBody String saveFile(@RequestPart("file") MultipartFile file) throws IOException, DocumentNotSavedException { 

    String targetPath = null; 
    if (file != null) { 
     String repoDirectoryPath = "SOME_REPO_PATH";   
     String uniqueFileName = FileUtil.getUniqueFileName(repoDirectoryPath, file.getOriginalFilename()); 
     File targetFile = new File(repoDirectoryPath, uniqueFileName); 
     targetPath = targetFile.getCanonicalPath(); 

     FileUtils.copyInputStreamToFile(file.getInputStream(), targetFile); 

    } else { 
     log.error("File is null"); 
     throw new DocumentNotSavedException("File data could not be saved"); 
    } 

    return targetPath; 
} 

RESTClient實現代碼

public String putDocument(File file,String fileName) throws RestClientException{ 
     ResponseEntity<String> response = null; 
     try { 
      File file = new File("SOME_100MB_FILE.pdf"); 
      byte[] fileBytes = new byte[(int)file.length()]; 
      LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap(); 
      ByteArrayResource contentsAsResource = new ByteArrayResource(fileBytes, fileName) { 
       @Override 
       public String getFilename() { 
        return this.getDescription(); 
       } 
      }; 
      map.add("file", contentsAsResource); 
      httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); 

      HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(map, httpHeaders); 

      response = restTemplate.exchange(serverUri, HttpMethod.POST, requestEntity, String.class); 
     } catch (Exception e) { 
      logger.error("Exception in put document service", e); 
      throw new RestClientException("Exception in put document service :",e); 
     } 
     return response.getBody(); 
} 

注:對於一個100MB的文件,駱駝路線記錄傳入的消息在服務被調用後的一秒內被記錄下來,但是我在大約15分鐘後看到了即將離任的日誌。我認爲生產者駱駝路線可能有問題。

回答