春季云数据流中春季webflux流出现问题

时间:2019-09-16 06:33:58

标签: spring-cloud spring-webflux spring-cloud-stream

我有自定义的Spring Cloud数据流源应用程序,该应用程序连接到其余端点并缓冲数据并发送到自定义接收器。我使用Spring webflux相同。如果我执行block()并收集所有可用数据并将其发送到消息Channel,一切都将正常工作。问题是我需要分块发送数据,因此需要将数据缓冲在流中,例如说有100K条记录并发送到消息通道。现在,当我尝试做缓冲区并将块发送到消息通道时,它会失败。

  

工作代码(阻止呼叫以收集所有数据并立即发送)

@InboundChannelAdapter(
    value = Source.OUTPUT
    poller = @Poller(fixedDelay = "120000", maxMessagesPerPoll = "100000")
public  MessageSource<List<MyDataDTO>> sendEdpiMessageToChannel() {
List<MyDataDTO> list=WebClient.create()
    .get()
    .uri(builder -> builder.scheme("https")
    .host("server_name")
    .path("/api/endpoint")                  
    .build())
    .header("Cookie",cookie)
    .accept(MediaType.APPLICATION_JSON)
    .exchange()
    .flatMapMany(clientResponse -> clientResponse.bodyToFlux(MyDataDTO.class))      
    .collectList()
    .block();                      
 return ()->MessageBuilder.withPayload(list).build();
}        
  

现在,我想将其缓冲并发送,而不是进行收集   并阻止通话,但这失败

     

源代码

@Scheduled(fixedDelay = 120000)
public  MessageSource<List<MyDataDTO>> sendEdpiMessageToChannel() {
List<MyDataDTO> list=WebClient.create()
    .get()
    .uri(builder -> builder.scheme("https")
    .host("server_name")
    .path("/api/endpoint")                  
    .build())
    .header("Cookie",cookie)
    .accept(MediaType.APPLICATION_JSON)
    .exchange()
    .flatMapMany(clientResponse -> clientResponse.bodyToFlux(MyDataDTO.class))//.subscribeOn(Schedulers.parallel())              
    .buffer(100000)
    .concatMap(streamRecordsList -> Mono.fromRunnable(()->sendToChannel(streamRecordsList));
}

@InboundChannelAdapter(
    value = Source.OUTPUT
)
public MessageSource<List<MyDataDTO>> sendToChannel(List<MyDataDTO> list ) 
{
    return ()->MessageBuilder.withPayload(list).build();
}
  

堆栈跟踪

2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT] 2019-09-16 06:27:47.859错误9 --- [schedule-1] osintegration .handler.LoggingHandler:org.springframework.messaging.MessagingException:调用方法失败;嵌套异常是java.lang.IllegalArgumentException:错误的参数数量 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.MethodInvokingMessageSource.doReceive(MethodInvokingMessageSource.java:117) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:160) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:250) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:360) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:329) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda $ null $ 1(AbstractPollingEndpoint.java:277) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda $ execute $ 0(ErrorHandlingTaskExecutor.java:57) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:55) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda $ createPoller $ 2(AbstractPollingEndpoint.java:274) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT] at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT] at java.util.concurrent.FutureTask.run(FutureTask.java:266) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 201(ScheduledThreadPoolExecutor.java:180) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在java.lang.Thread.run(Thread.java:748) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]原因:java.lang.IllegalArgumentException:参数数量错误 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在java.lang.reflect.Method.invoke(Method.java:498) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:246) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:230) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT]在org.springframework.integration.endpoint.MethodInvokingMessageSource.doReceive(MethodInvokingMessageSource.java:114) 2019-09-16T02:27:47.860-04:00 [APP / PROC / WEB / 0] [OUT] ...还有18个 2019-09-16T02:27:48.533-04:00 [CELL / 0] [OUT]容器变得健康

1 个答案:

答案 0 :(得分:0)

我使用下面的代码来工作

@Scheduled(fixedDelay = 120000)
public  MessageSource<List<MyDataDTO>> sendEdpiMessageToChannel() {
List<MyDataDTO> list=WebClient.create()
    .get()
    .uri(builder -> builder.scheme("https")
    .host("server_name")
    .path("/api/endpoint")                  
    .build())
    .header("Cookie",cookie)
    .accept(MediaType.APPLICATION_JSON)
    .exchange()
    .flatMapMany(clientResponse -> clientResponse.bodyToFlux(MyDataDTO.class))//.subscribeOn(Schedulers.parallel())              
    .buffer(100000)
    .concatMap(streamRecordsList -> Mono.fromRunnable(()->sendToChannel(streamRecordsList));
}

public void sendToChannel(List<MyDataDTO> list ) 
{
   this.source.output().send(MessageBuilder.withPayload(list).build());
}