没有共享数据源的远程分区

时间:2018-01-15 04:29:35

标签: spring spring-integration spring-batch

我正在编写一个远程分区作业,并且可以使用共享数据源(MySql)运行该作业,但是当我想运行我不想在主从和远程从站之间使用共享数据库的作业时,远程从站失败当它收到来自主服务器的消息时出现以下异常。

Caused by: org.springframework.batch.core.step.NoSuchStepException: No StepExecution could be located for this request: StepExecutionRequest: [jobExecutionId=1, stepExecutionId=2, stepName=remoteSlavePartition]

我该如何解决这个问题?以下是我用于工作的豆子。如果您需要更多的bean以获得更多清晰度,请告诉我。

@Bean
@Profile("master")
public PartitionHandler partitionHandler(MessagingTemplate messagingTemplate, PollableChannel replyPollableChannel) throws Exception {
    MessageChannelPartitionHandler partitionHandler = new MessageChannelPartitionHandler();

    partitionHandler.setStepName("remoteSlavePartition");
    partitionHandler.setGridSize(5);
    partitionHandler.setMessagingOperations(messagingTemplate);
    partitionHandler.setPollInterval(5000l);
    partitionHandler.setReplyChannel(replyPollableChannel);

    partitionHandler.afterPropertiesSet();

    return partitionHandler;
}

@Bean
@Profile("slave")
@ServiceActivator(inputChannel = "inboundRequests", outputChannel = "outboundStaging")
public StepExecutionRequestHandler stepExecutionRequestHandler() {
    StepExecutionRequestHandler stepExecutionRequestHandler =
            new StepExecutionRequestHandler();

    BeanFactoryStepLocator stepLocator = new BeanFactoryStepLocator();
    stepLocator.setBeanFactory(this.applicationContext);
    stepExecutionRequestHandler.setStepLocator(stepLocator);
    stepExecutionRequestHandler.setJobExplorer(this.jobExplorer);

    return stepExecutionRequestHandler;
}

@Bean
@Profile("master")
public IntegrationFlow amqpInboundForHandlingSlaveResponses(ConnectionFactory connectionFactory) {
    return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, responseQueue()))
                            .aggregate()
                            .channel(replyPollableChannel())
                            .get();
}

@Bean
@Profile("slave")
public PollableChannel outboundStaging() {
    return new QueueChannel();
}

@Bean
@Profile("slave")
public IntegrationFlow sendRepliesFlow(AmqpTemplate amqpTemplate) {
    return IntegrationFlows.from(outboundStaging())
            .handle(Amqp.outboundAdapter(amqpTemplate)
                    .defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT)
                    .routingKey("partition.responses"))
            .get();
}

@Bean
@Profile("slave")
public QueueChannel inboundRequests() {
    return new QueueChannel();
}

有没有什么方法可以让slave和master不使用相同的数据库然后在远程分区中运行作业?

1 个答案:

答案 0 :(得分:0)

共享数据源是远程分区的要求。原因是步骤的元数据保存在同一个存储库中。每个工人步骤仍然是同一工作的一个步骤,因此需要报告。