disconf-基於xml分佈式配置管理cronjob

本文介紹disconf如何管理cronjob的配置
spring的cronjob有2種實現方式:存入哦你job和scheduler
新建cronjob.properties,內容爲:
# cron job
task.pool.size=20
task.getMoney.delay=1000
task.getCar.cronExpression=*/1 * * * * ?
新建cronjob.xml,內容爲:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<!-- 定時get car -->
<bean id="getCar" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="cronJobService" />
<property name="targetMethod" value="getCar" />
</bean>
<bean id="getCarJob" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="getCar" />
<property name="cronExpression" value="${task.getCar.cronExpression}">
</property>
</bean>

<!-- task啓動列表 -->
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="getCarJob" />
</list>
</property>
</bean>

<!--處理任務 -->
<bean id="scheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="poolSize" value="${task.pool.size}" />
<property name="waitForTasksToCompleteOnShutdown" value="true" />
</bean>
<task:scheduled-tasks scheduler="scheduler">
<task:scheduled ref="cronJobService" method="getMoney"
fixed-delay="${task.getMoney.delay}" />
</task:scheduled-tasks>
</beans>
這個比較簡單

參考:https://github.com/knightliao/disconf/wiki
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章