Listener configuration

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:elasticjob="http://shardingsphere.apache.org/schema/elasticjob"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://shardingsphere.apache.org/schema/elasticjob
  8. http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd
  9. ">
  10. <!-- Configuration job registration center -->
  11. <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="my-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
  12. <!-- Configuration Job Bean -->
  13. <bean id="myJob" class="xxx.MyJob" />
  14. <elasticjob:job id="${myJob.id}" job-ref="myJob" registry-center-ref="regCenter" sharding-total-count="3" cron="0/1 * * * * ?" job-listener-types="simpleJobListener,distributeOnceJobListener">
  15. </elasticjob:job>
  16. </beans>

Job start

The xml that configures the Spring namespace is started through Spring, and the job will be automatically loaded.