【问题标题】:Disable InboundChannelAdapter / Poller with autoStartup false使用 autoStartup false 禁用 InboundChannelAdapter / Poller
【发布时间】:2022-02-05 01:54:12
【问题描述】:

在 Spring Integration 中,我想通过在 InboundChannelAdapter 上设置 autoStartup=false 来禁用轮询器。但是通过以下设置,我的轮询器都没有在我的 Tomcat 实例 1 和 Tomcat 实例 2 上触发。我有两个部署了相同代码的 Tomcat 实例。我希望在其中一个实例上禁用轮询器,因为我不希望同时在两个 Tomcat 实例上轮询相同的作业。

这是 InboundChannelAdapter:

@Bean
@InboundChannelAdapter(value = "irsDataPrepJobInputWeekdayChannel", poller = @Poller(cron="${batch.job.schedule.cron.weekdays.irsDataPrepJobRunner}", maxMessagesPerPoll="1" ), autoStartup = "${batch.job.schedule.cron.weekdays.irsDataPrepJobRunner.autoStartup}")
public MessageSource<JobLaunchRequest> pollIrsDataPrepWeekdayJob() {

    return () -> new GenericMessage<>(requestIrsDataPrepWeekdayJob());
}

属性文件如下。 Tomcat 实例 1 的属性文件:

# I wish for this job to run on Tomcat instance 1
batch.job.schedule.cron.riStateAgencyTransmissionJobRunner=0 50 14 * * *

# since autoStartup defaults to true, I do not provide:
#batch.job.schedule.cron.riStateAgencyTransmissionJobRunner.autoStartup=true

# I do NOT wish for this job to run on Tomcat instance 1
batch.job.schedule.cron.weekdays.irsDataPrepJobRunner.autoStartup=false

# need to supply as poller has a cron placeholder
batch.job.schedule.cron.weekdays.irsDataPrepJobRunner=0 0/7 * * * 1-5

Tomcat 实例 2 的属性文件:

# I wish for this job to run on Tomcat instance 2
batch.job.schedule.cron.weekdays.irsDataPrepJobRunner=0 0/7 * * * 1-5

# since autoStartup defaults to true, I do not provide:
#batch.job.schedule.cron.weekdays.irsDataPrepJobRunner.autoStartup=true

# I do NOT wish for this job to run on Tomcat instance 2
batch.job.schedule.cron.riStateAgencyTransmissionJobRunner.autoStartup=false

# need to supply as poller has a cron placeholder
batch.job.schedule.cron.riStateAgencyTransmissionJobRunner=0 50 14 * * *

属性文件作为 VM 选项传递,例如“-Druntime.scheduler=dev1”。我无法使用“-”作为 cron 表达式禁用其中一个 JVM 上的轮询器——类似于此处的问题:Poller annotation with cron expression should support a special disable character

我能够从 Tomcat 实例 1 或 Tomcat 实例 2 手动调用作业的目标正在发挥作用。我对上述设置的问题是,没有一个轮询器按照他们的 cron 表达式触发。

【问题讨论】:

    标签: spring-batch spring-integration


    【解决方案1】:

    考虑研究一种领导选举模式:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#leadership-event-handling

    这样,默认情况下这些端点处于未启动状态并处于相同角色。选举将选择一个领导者,并且只开始这个。

    当然,必须有一些共享的外部服务来控制领导力。

    【讨论】:

      猜你喜欢
      • 2021-02-17
      • 2019-06-10
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多