日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring-boot集成elastic-job 并实现http类型作业

發布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring-boot集成elastic-job 并实现http类型作业 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.安裝zookeeper 3.6.3(elastic-job實現http類型作業 要求zookeeper版本在3.6以上)

1.1 pom.xml

<dependency><groupId>org.apache.shardingsphere.elasticjob</groupId><artifactId>elasticjob-lite-spring-boot-starter</artifactId><version>3.0.1</version></dependency><dependency><groupId>org.apache.shardingsphere.elasticjob</groupId><artifactId>elasticjob-lite-lifecycle</artifactId><version>3.0.1</version></dependency>

1.2 配置文件

elasticjob.reg-center.server-lists=127.0.0.1:2181 elasticjob.reg-center.namespace=elastic-job-zhangmr elasticjob.reg-center.maxRetries=3 elasticjob.reg-center.baseSleepTimeMilliseconds=1000 elasticjob.reg-center.maxSleepTimeMilliseconds=3000 elasticjob.reg-center.session-timeout-milliseconds=3000 elasticjob.reg-center.connection-timeout-milliseconds=3000 elasticjob.shardingTotalCount = 4

1.3 demo代碼

@Service public class TaskServer {@Value("${elasticjob.reg-center.server-lists}")private String serverLists;@Value("${elasticjob.reg-center.namespace}")private String namespace;@Value("${elasticjob.shardingTotalCount}")private int shardingTotalCount;@Autowiredprivate ZookeeperRegistryCenter zookeeperRegistryCenter;public void addTask(){JobConfiguration jobConfiguration = JobConfiguration.newBuilder("javaHttpJob", shardingTotalCount).setProperty(HttpJobProperties.URI_KEY, "http://127.0.0.1:8082/job/excutor").setProperty(HttpJobProperties.METHOD_KEY, "POST").setProperty(HttpJobProperties.DATA_KEY, "source=ejob").cron("* * * * * ? *").shardingItemParameters("0=test0,1=test1, 2=test2, 3=test3").failover(true).misfire(true).overwrite(true).build();ScheduleJobBootstrap scheduleJobBootstrap = new ScheduleJobBootstrap(zookeeperRegistryCenter, "HTTP", jobConfiguration);scheduleJobBootstrap.schedule();} }

1.4 調用添加方法

@RestController @RequestMapping("/job") public class TaskController {@Autowiredprivate TaskServer taskServer;@RequestMapping("/excutor")@ResponseBodypublic String excutor(){System.out.println("123");return "log info success";}@RequestMapping("/add")public String add(){taskServer.addTask();return "log info success";} }

1.5 查看zookeeper信息

1.6 查看接口文本信息

注意 :一開始使用linux服務器上的zookeeper3.6.3,一直連接不上zookeeper ,注冊不上,后來在本地安裝了個zookeeper3.6.3 使用127.0.0.1:2181 可以正常連接(原因是我的linux配置太低,可以把elasticjob.reg-center.session-timeout-milliseconds=300000 elasticjob.reg-center.connection-timeout-milliseconds=300000 這兩個參數調大就可以連上)

總結

以上是生活随笔為你收集整理的spring-boot集成elastic-job 并实现http类型作业的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。