java - Spring 集成 DSL 关闭策略
问题描述
目前我有这个流程
package com.example.demo.flow;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.dsl.*;
import org.springframework.integration.dsl.channel.MessageChannels;
import org.springframework.integration.file.dsl.Files;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.concurrent.Executors;
/**
* Created by on 03/01/2020.
*/
@Component
@Slf4j
public class TestFlow {
@Bean
public StandardIntegrationFlow errorChannelHandler() {
return IntegrationFlows.from("testChannel")
.handle(o -> {
log.info("Handling error....{}", o);
}).get();
}
@Bean
public IntegrationFlow testFile() {
IntegrationFlowBuilder testChannel = IntegrationFlows.from(Files.inboundAdapter(new File("d:/input-files/")),
e -> e.poller(Pollers.fixedDelay(5000L).maxMessagesPerPoll(5)
.errorChannel("testChannel")))
.channel(MessageChannels.executor(Executors.newFixedThreadPool(5)))
.transform(o -> {
throw new RuntimeException("Failing on purpose");
}).handle(o -> {
});
return testChannel.get();
}
}
我计划由于关闭而停止此流程,但可能有一些文件是流程的一部分。如果我关闭集成流程,当前正在处理的文件是否仍会完成,或者它们将被停止,可能会杀死它们的线程?
解决方案
如果停止但不破坏,则过程中的所有内容都将得到妥善处理。只有新数据将从源或消息通道发出。当您关闭它时,这也是一种自然的优雅关闭行为ApplicationContext
:它首先停止 bean,让它们完成正在进行的任何事情,然后才销毁它们。
因此,到目前为止,您应该对自己的意图感到满意。请与我们分享您的经验(如果不是这样) - 如果需要,我们将尽快进行适当的修复。关键是停止阶段的目标确实是不发出新数据,而是让现有处理优雅地完成。在文档中查看更多信息:https ://docs.spring.io/spring-integration/docs/current/reference/html/system-management.html#jmx-shutdown
推荐阅读
- java - 如何调用其中包含实体的请求?
- android - 刷新控件在 Android -React Native 上不起作用
- postgresql - Postgres 函数:循环遍历记录并返回单个值
- prediction - Mxnet 预测训练使用 rmse 但有些问题
- react-native - 【ReactNative】如何执行显示:渲染屏幕前“none”
- react-native - 如何使用 expo 为传感器应用程序创建 csv 文件
- ruby-on-rails - 同一模型中的 Rails 关联取决于属性
- python - 我如何使pygame中的矩形位于中间
- java - 在不正确了解 xml 的情况下从 android studio 的拖放功能学习 android 应用程序开发会更好吗?
- php - 开始拖动时,Fullcalendar 滚动到顶部