【问题标题】:camel-jetty http proxy taking too much time for large request streams (file upload)camel-jetty http 代理为大型请求流(文件上传)花费了太多时间
【发布时间】:2016-08-04 22:36:47
【问题描述】:

我为我的项目的安静服务创建了一个骆驼码头 http 代理网桥,用于文档下载/上传。调用这些服务来获取/上传不同类型的文档,大多数情况下文件大小超过 100MB。

当我直接调用上传休息服务(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 Service(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 分钟后看到传出日志。我认为制片人骆驼路线可能有问题。

【问题讨论】:

    标签: file-upload apache-camel jetty http-proxy jbossfuse


    【解决方案1】:

    骆驼2.17.0有一个改进,可以use response input stream directly in http producer

    您可以在您的路线上试用最新的 Camel 2.17.x 版本 (2.17.3) 吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 2023-03-20
      • 2014-03-22
      • 1970-01-01
      • 2015-06-05
      • 2018-03-19
      相关资源
      最近更新 更多