TL;DR
即使 文档 说这是默认行为.我们如何允许 SCDF 使用 Java DSL 同时运行同一任务的多个实例来启动任务?为了让事情变得更有趣,例如,当使用 curl 直接命中其余端点时,多次启动相同的任务可以正常工作.
Spring Cloud Data Flow does not allow multiple executions of the same Task even though the documentation says that this is the default behavior. How can we allow SCDF to run multiple instances of the same task at the same time using the Java DSL to launch tasks? To make things more interesting, launching of the same task multiple times works fine when directly hitting the rest enpoints using curl for example.
背景:
我有一个 Spring Cloud 数据流任务,我已经在 Spring Cloud 数据流 UI 仪表板
I have a Spring Cloud Data Flow Task that I have pre-registered in the Spring Cloud Data Flow UI Dashboard
@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 } }我正在使用 任务 Java DSL 在其他一些主程序中:
I am launching this task using the Task Java DSL in some other main program :
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<>());这第一次运行得很好;但是,当我尝试重新运行上述代码时,在上述程序中出现以下异常:
This works perfectly fine the first time; however, when I try to rerun the above code, I get the following exception in the above program :
[main] DEBUG org.springframework.web.client.RestTemplate - Response 409 CONFLICTSCDF 服务器日志显示了类似的问题:
The SCDF server logs show a similar issue :
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有趣的部分是,如果我使用 API 指南
The interesting part is that I am able to launch multiple instances of the same task if I use the curl command as shown in the API guide
问题:
根据 SCDF 任务文档,默认情况下可以重新运行任务.无需额外配置即可重新运行相同的任务;然而,事实似乎恰恰相反.SCDF 默认不允许任务重新运行?
As per the SCDF Task documentation, a Task can be rerun by default. There is no additional configuration required to be able to rerun the same task; however, it looks like the opposite is true. SCDF does not allow a task to be rerun by default?
我尝试按照建议添加 Spring 集成 jar 并将 spring.cloud.task.single-instance-enabled 属性显式设置为 false,但开始遇到 NoClassDefFoundError 相关问题.我也尝试将此属性传递给 Task.launch 方法,但这并没有解决问题.
I tried adding Spring integration jars as suggested and explicitly set the spring.cloud.task.single-instance-enabled property to false but started running into NoClassDefFoundError related issues. I also tried passing this property to the Task.launch method but that did not solve the issue.
为什么同一个任务在使用 curl 命令时可以多次重新启动,而在使用 Java DSL 时不能多次重新启动?
Why can the same task be relaunched multiple times when using the curl command but cannot be relaunched multiple times when using the Java DSL?
推荐答案在这种情况下,您似乎正在尝试重新创建任务定义.您应该只需要创建一次任务定义.根据这个定义,您可以多次启动.例如:
In this case it looks like you are trying to recreate the task definition. You should only need to create the task definition once. From this definition you can launch multiple times. For example:
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<>()); executionId = task.launch(new ArrayList<>()); executionId = task.launch(new ArrayList<>());更多推荐
Spring Cloud Data Flow:无法启动同一任务的多个实例
发布评论