【发布时间】:2021-05-12 15:32:24
【问题描述】:
TL;DR
Spring Cloud Data Flow 不允许多次执行同一个任务,即使 documentation 表示这是默认行为。我们如何允许 SCDF 使用 Java DSL 启动任务同时运行同一任务的多个实例?为了让事情变得更有趣,例如,在使用 curl 直接点击其余端点时,多次启动相同的任务可以正常工作。
背景:
我在Spring Cloud Data Flow UI Dashboard预注册了一个Spring Cloud Data Flow Task
@SpringBootApplication
@EnableTask
public class TaskApplication implements ApplicationRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskApplication.class);
public static void main(String[] args) {
SpringApplication.run(TaskApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws InterruptedException {
//Some application code
}
}
我在其他一些主程序中使用Task Java DSL 启动这个任务:
URI dataFlowUri = URI.create(scdfUri);
DataFlowOperations dataFlowOperations = new DataFlowTemplate(dataFlowUri);
Task task = Task.builder(dataFlowOperations).name("Task1").definition("a:task1")
.description("Task launched from DSL").build();
long executionId = task.launch(new ArrayList<>());
这第一次工作得很好;但是,当我尝试重新运行上述代码时,在上述程序中出现以下异常:
[main] DEBUG org.springframework.web.client.RestTemplate - Response 409 CONFLICT
SCDF 服务器日志显示类似的问题:
2021-05-12 15:12:31.387 WARN 1 --- [nio-9393-exec-3] o.s.c.d.s.c.RestControllerAdvice : Caught exception while handling a request: Cannot register task Task1 because another one has already been registered with the same name
有趣的是,如果我使用 curl 命令(如 API guide 所示),我可以启动同一任务的多个实例
问题:
-
根据SCDF Task documentation,默认情况下可以重新运行任务。无需额外配置即可重新运行相同的任务;但是,看起来情况恰恰相反。 SCDF默认不允许任务重新运行?
-
我尝试按照建议添加 Spring 集成 jar,并将
spring.cloud.task.single-instance-enabled属性显式设置为 false,但开始遇到NoClassDefFoundError相关问题。我也尝试将此属性传递给Task.launch方法,但这并没有解决问题。 -
为什么使用 curl 命令可以多次重启同一个任务,而使用 Java DSL 时不能多次重启?
【问题讨论】:
标签: java spring-cloud-dataflow spring-cloud-task