1

我目前在 Spring Cloud Data Flow 中的 Tasks 调用遇到问题。

我有一个在 SCDF 上注册的 Spring Batch(包含单任务步骤作业)应用程序和一个基于此应用程序的任务定义。在我第一次启动此任务期间,我使用了几个作业参数/参数。由于我现在知道的一个原因,我所有的后续启动都被我使用的第一组参数覆盖。

我正在使用 SCDF 1.4.0 + MSSQL 数据库,但是使用 SCDF 1.3.2 + H2 或 MSSQL 也会发生同样的行为。

批处理配置.java

    @Configuration
    public class BatchConfig {

        @Autowired
        TaskletStep taskletStep;

        @Autowired
        public JobBuilderFactory jobBuilderFactory;

        @Autowired
        public StepBuilderFactory stepBuilderFactory;


        @Bean
        public Step step1() {
            return stepBuilderFactory.get("step1")
                    .tasklet(taskletStep)
                    .build();
        }

        @Bean
        public Job job() throws Exception {
            return jobBuilderFactory.get("job")
                    .incrementer(new RunIdIncrementer())
                    .start(step1())
                    .build();
        }
}

TaskletStep.java:

@Configuration
@StepScope
public class TaskletStep  implements Tasklet{


    @Value("#{jobParameters['filePath']}")
    private String filePath;

    @Value("#{jobParameters['informante']}")
    private String informante;

    @Autowired
    RemessaParser remessaParserService;

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        GICLogger.info("Recebido job com path: " + filePath + " para o informante "+ informante);
        try{
            Path remessa = Paths.get(filePath);
            if(Files.exists(remessa)){
                String idRemessa = remessaParserService.remessaReader(remessa, informante);
                GICLogger.info("### TaskletStep:" + idRemessa + " é o ID da Remessa!");
                return RepeatStatus.FINISHED;
            }else{
                GICLogger.error("Não foi possível encontrar a remessa em "+filePath);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return RepeatStatus.FINISHED;
    }
}

我的启动命令:

dataflow> task launch negTask --arguments "filePath=/tmp/jars/remessa.txt informante=CaixaB --spring.cloud.task.closecontext_enable=false"

申请日志:

2018-04-04 13:33:28 [main] INFO cbgnBatchNegativacaoApp - 在 13.938 秒内启动 BatchNegativacaoApp(JVM 运行时间为 14.599)

2018-04-04 13:33:28 [main] INFO osbabJobLauncherCommandLineRunner - 使用以下命令运行默认命令行:[filePath=/tmp/jars/remessa.txt,informante=Caixa,--spring.cloud.task.closecontext_enable=false, --spring.cloud.task.executionid=17]

2018-04-04 13:33:28 [main] INFO osbclsupport.SimpleJobLauncher - Job: [SimpleJob: [name=job]] 使用以下参数启动:[{filePath=/home/enrico/PROJETOS/GIC/java/ remessa.txt, -spring.cloud.task.executionid=8, informante=Caixa, -spring.cloud.task.closecontext_enable=false, run.id=12, time=1522842134819}]

你们知道为什么会发生吗?

感谢您的关注和任何意见!

最好的问候,恩里科

4

1 回答 1

3

嗨,Enrico,我是相似性问题,试试吧,它的工作原理。

@Bean
@Qualifier("load")
public Job load(JobCompletionNotificationListener listener, Step step1, 
@Qualifier("stepValidation") Step stepValidation) {
    return jobBuilderFactory.get("load")
            .incrementer(new SampleIncrementer())
            .listener(listener)
            .flow(stepValidation)
            .next(step1)
            .end().build();
}

public class SampleIncrementer implements JobParametersIncrementer {

    public JobParameters getNext(JobParameters parameters) {
        if (parameters==null || parameters.isEmpty()) {
            return new JobParametersBuilder().addLong("run.id", 1L).toJobParameters();
        }

        long id = parameters.getLong("run.id",1L) + 1;
        return new JobParametersBuilder().addLong("run.id", id)
            .toJobParameters();
    }
}
于 2018-04-07T15:16:48.633 回答