定时任务集群部署

<dubbo:monitor protocol="registry"/>
<dubbo:application name="oolp">
<!--设置dubbo优雅停机,超时30秒,缺省为10秒-->
<dubbo:parameter key="shutdown.timeout" value="30000"/>
</dubbo:application>
<!-- 注册中心的ip地址 -->
<dubbo:registry protocol="zookeeper" address="${zkservers}"/>
<!--&lt;!&ndash; 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中所有的类 &ndash;&gt;-->
<dubbo:annotation package="com.hispeed.teamcontract.service.impl" />
<dubbo:consumer check="false" retries="0" timeout="12000"/>
<dubbo:protocol name="dubbo" port="20789"/>
<!--<dubbo:provider delay="-1" timeout="6000" retries="0"/>-->
<dubbo:provider timeout="12000" retries="0"/>
@Configuration
@ImportResource({ "classpath:config/*.xml" })
public class DubboConfig {
}


private ZKLeaderLatch zkLeaderLatch;

@Autowired
public ScheduledTaskServiceImpl(ZKLeaderLatch zkLeaderLatch) {
this.zkLeaderLatch = zkLeaderLatch;
}

@Scheduled(fixedRate = 1 * 60 * 1000)
@Override
public void teamContractScheduledTask() {
if(this.zkLeaderLatch.isLeader()){
    //定时执行任务
  }
}
com.boot.zookeeper.ZKLeaderLatch-|-[leaderLatch start....]
posted @ 2019-10-11 09:25  1192371135  阅读(798)  评论(0编辑  收藏  举报