将客户端REQUEST_ENTITY_PROCESSING设置为CHUNKED后,我丢失了文档

Nic*_*zza 8 java streaming http jersey

我有一个在Jetty上运行的REST Web服务.我想编写一个Java客户端,它使用相同的Web连接将大量文档分块到该休息服务.

我能够在这里建立一个基于Iterator的流媒体方法:

将文档流发送到Jersey @POST端点

除非您设置clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);因为Content-length未知,否则这不起作用.

虽然有些工作,但分块转移似乎丢失了一些文件.例如:

num_docs 500000
numFound 499249
Run Code Online (Sandbox Code Playgroud)

也许它发送的块像:

{some:doc}, {some:doc}, {some:doc}, {some:doc}, {some:doc}, {some:doc}, {some:do

所以我每次都在输掉一些?更新:我错了.

我该怎么做呢?还有什么想法可能会发生什么?

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.property(ClientProperties.CONNECT_TIMEOUT, (int)TimeUnit.SECONDS.toMillis(60));
    clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
    clientConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 100);
    clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, HttpClientFactory.createConnectionManager(name,
      metricRegistry, configuration));
    ApacheConnectorProvider connector = new ApacheConnectorProvider();
    clientConfig.connectorProvider(connector);
    clientConfig.register(new ClientRequestFilter() {
    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
      List<Object> orig = requestContext.getHeaders().remove(HttpHeaders.CONTENT_LENGTH);
      if (orig != null && !orig.isEmpty()) {
        requestContext.getHeaders().addAll("Length", orig);
      }
    }
    });
    clientConfig.register(new ClientRequestFilter() {
    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
      if (requestContext.getMediaType() != null &&
          requestContext.getMediaType().getType() != null &&
          requestContext.getMediaType().getType().equalsIgnoreCase("multipart")) {
        final MediaType boundaryMediaType = Boundary.addBoundary(requestContext.getMediaType());
        if (boundaryMediaType != requestContext.getMediaType()) {
          requestContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, boundaryMediaType.toString());
        }
        if (!requestContext.getHeaders().containsKey("MIME-Version")) {
          requestContext.getHeaders().putSingle("MIME-Version", "1.0");
        }
      }
    }
    });
Run Code Online (Sandbox Code Playgroud)

Nic*_*zza 3

关闭它 - 我不小心提前关闭了流,所以最后确实缺少文档,这给了我提示,要等到阻塞队列为空后再关闭执行器。