安裝Workbench以及kie-server
https://blog.csdn.net/chinrui/article/details/79018351
Workbench安裝說(shuō)明
https://hub.docker.com/r/jboss/drools-workbench-showcase/
kie-server安裝說(shuō)明
https://hub.docker.com/r/jboss/kie-server-showcase/
1.下載Workbench以及kie-server鏡像
docker pull jboss/drools-workbench-showcase
showcase繼承于jboss/drools-workbench:latest卓研,增加了默認(rèn)的用戶和角色库快,還增加了一些例子
docker pull jboss/kie-server-showcase:latest
2.啟動(dòng)
啟動(dòng)Workbench
docker run -p 8080:8080 -p 8001:8001 -d --name drools-wb jboss/drools-workbench-showcase:latest
啟動(dòng)kie-server
docker run -p 8180:8080 -d --name kie-server --link drools-wb:kie_wb jboss/kie-server-showcase:latest
docker run -p 8080:8080 -p 6001:8001 -d --name drools-wb jboss/drools-workbench-showcase:latest
3.登錄及使用Workbench
http://localhost:8080/drools-wb
使用用戶名及密碼登錄
USER PASSWORD ROLE ********************************************* admin admin admin,analyst,kiemgmt krisv krisv admin,analyst john john analyst,Accounting,PM sales-rep sales-rep analyst,sales katy katy analyst,HR jack jack analyst,IT
https://github.com/wildfly/quickstart
4.使用Workbench
4.1新建項(xiàng)目
4.2 Add Asset創(chuàng)建包、創(chuàng)建數(shù)據(jù)對(duì)象模型姥闪、規(guī)則文件尊浓、測(cè)試文件、發(fā)布規(guī)則
a.創(chuàng)建包
b.創(chuàng)建數(shù)據(jù)對(duì)象
Address模型
ApplyInfo模型
c.創(chuàng)建規(guī)則
規(guī)則名rule_001
可以看到同報(bào)名的數(shù)據(jù)對(duì)象自動(dòng)導(dǎo)入了
通過(guò)編輯器配置規(guī)則
d.創(chuàng)建測(cè)試場(chǎng)景testRule_001呈驶,增加fact
運(yùn)行測(cè)試場(chǎng)景
e.發(fā)布規(guī)則
首先設(shè)置 KieBase 與 KieSession苫耸,也就是配置 kmodule.xml 文件
5.kie-server
啟動(dòng)之后訪問(wèn)
http://localhost:8180/kie-server/services/rest/server/
kieserver/kieserver1!
通過(guò)Workbench查看服務(wù)器可以看到已經(jīng)關(guān)聯(lián)了kie-server
6.調(diào)用kie-server
依賴
<dependency>
<groupId>org.kie.server</groupId>
<artifactId>kie-server-client</artifactId>
<version>7.7.0.Final</version>
</dependency>
調(diào)用kie-server代碼
public class Main {
public static final String SERVER_URL = "http://localhost:6160/kie-server/services/rest/server";
public static final String USERNAME = "kieserver";
public static final String PASSWORD = "kieserver1!";
public static final String KIE_CONTAINER_ID = "com.gao:hellodrools:1.0.0";
public static void main(String[] args) {
// KisService 配置信息設(shè)置
KieServicesConfiguration kieServicesConfiguration =
KieServicesFactory.newRestConfiguration(SERVER_URL, USERNAME, PASSWORD, 10000L);
kieServicesConfiguration.setMarshallingFormat(MarshallingFormat.JSON);
// 創(chuàng)建規(guī)則服務(wù)客戶端
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfiguration);
RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
// 規(guī)則輸入條件
ApplyInfo applyInfo = new ApplyInfo();
applyInfo.setAge(19);
Address familyAddress = new Address();
familyAddress.setProvince("aa");
applyInfo.setFamilyAddress(familyAddress);
// 命令定義,包含插入數(shù)據(jù)杉武,執(zhí)行規(guī)則
KieCommands kieCommands = KieServices.Factory.get().getCommands();
List<Command<?>> commands = new LinkedList<>();
commands.add(kieCommands.newInsert(applyInfo, "applyInfo"));
commands.add(kieCommands.newFireAllRules());
ServiceResponse<ExecutionResults> results = ruleServicesClient.executeCommandsWithResults(KIE_CONTAINER_ID,
kieCommands.newBatchExecution(commands, "ksessionId"));
// 返回值讀取
ApplyInfo value = (ApplyInfo) results.getResult().getValue("applyInfo");
System.out.println(value);
}
}
java部署