Spring Batch远程分区 - 有时Master Step在所有分区步骤完成之前完成

时间:2018-01-29 18:54:09

标签: spring spring-integration spring-batch

我遇到了Spring Batch Remote Partitioning作业的问题,其中主步骤在所有分区(从属)步骤完成之前完成。这是随机发生的(大多数时候主步骤在所有分区步骤完成后完成)。 如果我的配置中遗漏了任何内容,请告诉我。

这是主要工作配置

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${activemq.url}"/>
    <property name="userName" value="${activemq.userName}"/>
    <property name="password" value="${activemq.password}"/>
</bean>

<int:channel id="requestsChannel"/>

<int-jms:outbound-channel-adapter connection-factory="connectionFactory"
                                  channel="requestsChannel"
                                  destination-name="${activemq.requestQueue}"/>

<int:channel id="replyChannel"/>

<int-jms:message-driven-channel-adapter connection-factory="connectionFactory"
                                        channel="replyChannel"
                                        destination-name="${activemq.replyQueue}"/>

<int:channel id="aggregatedReplyChannel">
    <int:queue/>
</int:channel>

<int:aggregator ref="partitionHandler"
                input-channel="replyChannel"
                output-channel="aggregatedReplyChannel"
                send-timeout="86420000"/>

掌握JMS配置:

@Autowired
private StepBuilderFactory stepBuilderFactory;

@Autowired
private DataSource raddAppDataSource;

@Autowired
private PlatformTransactionManager transactionManager;

@Bean
public Step processRadItems() {
    final TaskletStep step = stepBuilderFactory.get("processRadItems")
            .<RadItem,RadItem>chunk(1)
            .reader(pagingItemReader(null,null,null))
            .processor(itemProcessor())
            .writer(itemWriter())
            .build();
    step.setTransactionManager(transactionManager);
    step.setStepExecutionListeners(new StepExecutionListener[]{radStepListener()});
    return step;
}

@Bean
@StepScope
public RadItemProcessorJob itemProcessor() {
    return new RadItemProcessorJob();
}

@Bean
public NoOpItemWriter itemWriter() {
    return new NoOpItemWriter();
}

@Bean
public RadStepListener radStepListener() {
    return new RadStepListener();
}

@Bean
@StepScope
public JdbcPagingItemReader pagingItemReader(@Value("#{stepExecutionContext['mod.divisor']}") Object modDivisor,
                                             @Value("#{stepExecutionContext['mod.remainder']}") Object modRemainder,
                                             @Value("#{jobParameters['setId']}") Long setId) {
    final JdbcPagingItemReader pagingItemReader = new JdbcPagingItemReader();
    pagingItemReader.setDataSource(raddAppDataSource);
    final SqlPagingQueryProviderFactoryBean sqlFactoryBean = new SqlPagingQueryProviderFactoryBean();
    sqlFactoryBean.setSelectClause("select rad_item_id, item_oid,coverage_start_date, coverage_end_date, item_status_code, rad_set_id, reprocess_type");
    sqlFactoryBean.setFromClause("from rad_item");
    sqlFactoryBean.setWhereClause("where rad_set_id = :setId and item_status_code in ('SELECTED','PROCESSED','REVIEWING') and mod(rad_item_id, :modDivisor) = :modRemainder");
    sqlFactoryBean.setSortKey("rad_item_id");
    sqlFactoryBean.setDataSource(raddAppDataSource);
    try {
        pagingItemReader.setQueryProvider(sqlFactoryBean.getObject());
    } catch (Exception e) {
        logger.error("Error creating pagingItemReader",e);
        throw new RuntimeException(e);
    }
    initParameterValues(pagingItemReader, modDivisor, modRemainder, setId);

    pagingItemReader.setPageSize(1);
    pagingItemReader.setRowMapper(new RadItemRowMapper());
    return pagingItemReader;
}

private void initParameterValues(JdbcPagingItemReader pagingItemReader, Object modDivisor, Object modRemainder, Long setId) {
    final Map<String,Object> parameterValues = new HashMap<>();
    parameterValues.put("modDivisor",modDivisor);
    parameterValues.put("modRemainder",modRemainder);
    parameterValues.put("setId",setId);
    pagingItemReader.setParameterValues(parameterValues);
}

@Bean
public StepExecutionRequestHandler stepExecutionRequestHandler() {
    final StepExecutionRequestHandler stepExecutionRequestHandler =  new StepExecutionRequestHandler();
    stepExecutionRequestHandler.setJobExplorer(jobExplorer());
    stepExecutionRequestHandler.setStepLocator(stepLocator());
    return stepExecutionRequestHandler;
}

@Bean
public JobExplorer jobExplorer() {
    try {
        final JobExplorerFactoryBean jobExplorerFactory = new JobExplorerFactoryBean();
        jobExplorerFactory.setDataSource(raddAppDataSource);
        jobExplorerFactory.afterPropertiesSet();
        return jobExplorerFactory.getObject();
    } catch (Exception e) {
        logger.error("Error creating JobExplorer Bean",e);
        throw new RuntimeException(e);
    }
}

@Bean
public StepLocator stepLocator() {
    return new BeanFactoryStepLocator();
}

从属 - 工作配置:

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${activemq.url}"/>
    <property name="userName" value="${activemq.userName}"/>
    <property name="password" value="${activemq.password}"/>
</bean>
<int:channel id="requestChannel"/>

<int-jms:message-driven-channel-adapter connection-factory="connectionFactory"
                                        destination-name="${activemq.requestQueue}"
                                        channel="requestChannel"/>

<int:channel id="replyChannel"/>

<int-jms:outbound-channel-adapter connection-factory="connectionFactory"
                                  destination-name="${activemq.replyQueue}"
                                  channel="replyChannel"/>

<int:service-activator input-channel="requestChannel"
                       output-channel="replyChannel"
                       ref="stepExecutionRequestHandler"/>

从属JMS配置:

{{1}}

0 个答案:

没有答案