1. 部署xxl-job調(diào)度中心
此處略,請(qǐng)自行百度。下面重點(diǎn)介紹如何將php項(xiàng)目接入xxl-job調(diào)度。
2. 整合xxl-job調(diào)度系統(tǒng)
核心是使用xxl-job的GLUE運(yùn)行模式,通過一段php代碼片段,調(diào)用遠(yuǎn)程的http資源。
2.1 創(chuàng)建執(zhí)行器項(xiàng)目
參考執(zhí)行器示例項(xiàng)目, xxl-job-executor-samples/xxl-job-executor-sample-springboot,修改下其中的 application.properties 文件,內(nèi)容如下:
# 執(zhí)行器項(xiàng)目使用的端口號(hào) server.port=8585 # no web #spring.main.web-environment=false # log config logging.config=classpath:logback.xml ### 調(diào)度中心地址 xxl.job.admin.addresses=http://127.0.0.1:8081/job-admin ### xxl-job, access token xxl.job.accessToken= ### xxl-job executor appname xxl.job.executor.appname=xxl-job-executor-base ### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null xxl.job.executor.address= ### xxl-job executor server-info xxl.job.executor.ip=127.0.0.1 xxl.job.executor.port=9999 ### xxl-job executor log-path xxl.job.executor.logpath=xxl-job-log ### xxl-job executor log-retention-days xxl.job.executor.logretentiondays=30
2.2 新增執(zhí)行器
在調(diào)度中心的管理界面,新增一個(gè)執(zhí)行器,執(zhí)行器的相關(guān)信息必須與【2.1】步驟中的配置保持一致,如下:
注意:此處的機(jī)器地址,在新版中必須帶上協(xié)議名稱,如:http。
2.3 部署執(zhí)行器項(xiàng)目
將編譯好的 xxl-job-executor-sample-springboot-2.2.1-SNAPSHOT.jar 包,復(fù)制到php項(xiàng)目所在的機(jī)器上,并啟動(dòng)。啟動(dòng)命令為:
java -jar -Dfile.encoding=utf-8 "xxl-job-executor-sample-springboot-2.2.1-SNAPSHOT.jar"
2.4 新增GLUE模式任務(wù)
執(zhí)行器選擇【2.2】步驟中新建的執(zhí)行器即可,運(yùn)行模式選擇【GLUE(PHP)】。
2.5 編寫php代碼片段
在任務(wù)列表中,找到之前新建的GLUE任務(wù),然后在對(duì)應(yīng)的操作欄中,選擇【GLUE IDE】菜單,進(jìn)入xxl-job內(nèi)置的web編輯器,即可編寫與業(yè)務(wù)相關(guān)的php代碼。
示例內(nèi)容如下:
<?php $url = "https://www.baidu.com/"; $result = file_get_contents($url); var_dump($result); exit(0); ?>
注意:
① 腳本任務(wù)通過 Exit Code 判斷任務(wù)執(zhí)行結(jié)果,0 成功,-1(非0狀態(tài)碼)失敗。
② 調(diào)度過程中,將會(huì)在 gluesource 目錄(位于日志根目錄下)下,生成一個(gè)臨時(shí)的php文件,文件內(nèi)容即為步驟【2.5】中編寫的代碼片段。
到此這篇關(guān)于php項(xiàng)目接入xxl-job調(diào)度系統(tǒng)的文章就介紹到這了,更多相關(guān)php項(xiàng)目接入xxl-job內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/tdcqfyl/article/details/121929060