java - 如何根据一些 Kafka 事件暂停和恢复 spring 批处理步骤
问题描述
我们正在尝试创建一个中央批处理服务,它将在远程(微)服务中调用批处理。在此期间,我们希望暂停步骤执行,直到远程服务没有响应批处理服务。这可以通过 Spring Batch 实现吗?
解决方案
您可以尝试实现 StepListener,其中您有 beforeStep 和 afterStep 方法,您可以在 beforeStep 方法调用中进行控制以等待其他服务调用完成其执行
public class StepTwoListener implements StepExecutionListener {
@Override
public void beforeStep(StepExecution stepExecution) {
long start = System.currentTimeMillis();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Sleep time in ms = "+(System.currentTimeMillis()-start));
System.out.println("Before Step Execution");
}}
你可以在你的步骤中使用监听器
@Bean
public Step stepTwo() {
return stepBuilderFactory.get("stepTwo").tasklet(new StepTwo()).listener(new StepTwoListener()).build();
}
推荐阅读
- python-3.x - 通过 Networkx 中的属性值将颜色设置为节点组
- mongodb - 如何使用 ansible 设置 mongodb 副本集
- angular - 检查数组值并更改输入 isCheck(函数)
- php - Laravel 8 - 一对多关系总数不起作用
- ckeditor - CKEditor 5 - 在提及中使用 HTML
- c++ - 具有自定义类型和比较器的 C++ 优先级队列不起作用
- python - 从表中提取特定的href
- javascript - React.js 中的相对导入
- python - 如何在 CSV 文件中显示嵌套字典
- firebase - Flutter Firebase 登录中的一些问题