简体   繁体   English

如何在集成中使用执行器进行并行处理

[英]How to use executor to parallel processing in integration

I want to read files from FTP and process them.我想从 FTP 读取文件并处理它们。 I use 'executorchannel', but 'executorchannel' won't stop receiving.我使用“executorchannel”,但“executorchannel”不会停止接收。 However, when the processing speed can't keep up, FTP keeps reading.但是,当处理速度跟不上时,FTP 一直在读。 When the files are read too much, an 'over head' exception appears.当文件读取过多时,会出现“开销”异常。 How to solve this problem如何解决这个问题呢

public IntegrationFlow processFileFlow() {
        //dsl
        return IntegrationFlows
                .from("ftpFileChannel")
                .enrichHeaders(h -> h.header(MessageHeaders.ERROR_CHANNEL, "exceptionChannel", true))
                .transform(transformer())
                .transform(new MyTransformer(zipProperties))
                .split()
                //.channel(MessageChannels.executor(Executors.newFixedThreadPool(3)))
                .route("headers['type']",
                        mapping -> mapping.async(true)
                                .resolutionRequired(false)
                                .ignoreSendFailures(true)
                                .subFlowMapping(DataTypeEnum.DELIVERY_DATA.getCode(),
                                        sf -> sf.channel(MessageChannels.executor(Executors.newFixedThreadPool(2,Executors.privilegedThreadFactory())))
                                                .publishSubscribeChannel(
                                                        c -> c.subscribe(s -> s.handle("fileProcess", "processDeliveryData")))
                                                .bridge())
                                .subFlowMapping(DataTypeEnum.PLACE_DATA.getCode(),
                                        sf -> sf.channel(c -> c.queue(5))
                                                .publishSubscribeChannel(
                                                        c -> c.subscribe(s -> s.handle("fileProcess", "processPlaceData")))
                                                .bridge()
                                ))
                .aggregate(t -> t
                        //t.correlationStrategy(c -> c.getHeaders().get("file_remoteFile"))
                        .outputProcessor(o -> new EventDto(o.getMessages().stream().map(m -> ((EncryptDataDto) m.getPayload()).getEventEntity()).collect(Collectors.toList())))
                )
                .handle("fileProcess", "endHandler", e -> e.advice(after()))
                .get();
    }

Spring Integration provides a CallerBlocksPolicy rejected execution handler. Spring 集成提供了一个CallerBlocksPolicy拒绝执行处理程序。

Use a task executor with a fixed thread pool and a bounded queue, with this policy to control the concurrency.使用具有固定线程池和有界队列的任务执行器,使用此策略来控制并发。 When the queue is full, the poller thread will block until space is made available by a task completing.当队列已满时,轮询线程将阻塞,直到任务完成提供可用空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM