长情的刺猬 · 2023年618活动什么时候开始?包含淘宝、 ...· 1 月前 · |
安静的麻辣香锅 · Flutter Text ...· 2 月前 · |
淡定的红薯 · How to modify ...· 1 年前 · |
豪爽的香槟 · python - Painting ...· 1 年前 · |
低调的数据线 · 如何解决C++中需要批量编写多个函数重载的问 ...· 1 年前 · |
KIE(Knowledge Is Everything),知识就是一切的简称。JBoss一系列项目的总称,在《Drools使用概述》章节已经介绍了KIE包含的大部分项目。它们之间有一定的关联,通用一些API。比如涉及到构建(building)、部署(deploying)和加载(loading)等方面都会以KIE作为前缀来表示这些是通用的API。
无论是Drools还是JBPM,生命周期都包含以下部分:
Fact对象是指在使用Drools 规则时,将一个普通的JavaBean对象插入到规则引擎的 WorkingMemory当中的对象。规则可以对Fact对象进行任意的读写操作。Fact对象不是对原来的JavaBean对象进行Clone,而是使用传入的JavaBean对象的引用。规则在进行计算时需要的应用系统数据设置在Fact对象当中,这样规则就可以通过对Fact对象数据的读写实现对应用数据的读写操作。
Fact对象通常是一个具有getter和setter方法的POJO对象,通过getter和setter方法可以方便的实现对Fact对象的读写操作,所以我们可以简单的把 Fact 对象理解为规则与应用系统数据交互的桥梁或通道。 当Fact对象插入到WorkingMemory当中后,会与当前WorkingMemory当中所有的规则进行匹配,同时返回一个FactHandler对象。FactHandler对象是插入到WorkingMemory当中Fact对象的引用句柄,通过FactHandler对象可以实现对Fact对象的删除及修改等操作。
前面的实例中通过调用insert方法将Product对象插入到WorkingMemory当中,Product对象插入到规则中之后就是说为的FACT对象。如果需要插入多个FACT对象,多次调用insert方法,并传入对应FACT对象即可。
Starting KIE (drools 7.10):
cd /opt/jbpm-server-7.10.0.Final-dist/bin/
. standalone.sh
open a web browser and go to localhost:8080/jbpm-console
Add Asset -> Data Object ** Data Object: ShoppingCart
Create new field ** Id: totalPrice ** Label: Total Price ** Type: BigDecimal
Save (upper right corner)
package npou.npproj;
* This class was automatically generated by the data modeler tool.
public class ShoppingCart implements java.io.Serializable {
static final long serialVersionUID = 1L;
@org.kie.api.definition.type.Label(value = "Total Price")
private java.math.BigDecimal totalPrice;
public ShoppingCart() {
public ShoppingCart(java.math.BigDecimal totalPrice) {
this.totalPrice = totalPrice;
public java.math.BigDecimal getTotalPrice() {
return this.totalPrice;
public void setTotalPrice( java.math.BigDecimal totalPrice ) {
this.totalPrice = totalPrice;
Add Asset -> Guided Rule
Resource Name: Apply Tall Order Discount
Enter details as below
View Source should return
package npou.npproj;
import java.lang.Number;
rule "Apply Tall Order Discount"
dialect "mvel"
$sc : ShoppingCart( $tp : totalPrice >= 10000.0B )
modify( $sc ) {
setTotalPrice( $tp*0.9 )
We need to ad no-loop attribute
package com.nobleprog.npproj;
import java.lang.Number;
rule "Apply Tall Order Discount"
dialect "mvel"
no-loop true
$sc : ShoppingCart( $tp : totalPrice >= 10000.0B )
modify( $sc ) {
setTotalPrice( $tp*0.9 )
We want to apply discounts according to the table below: 0 - 9,999 -> 0% 10,000 - 49,999 -> 10% 50,000 - 79,999 -> 12% 80,000 - above -> 15%
package npou.npproj;
//from row number: 1
rule "Row 1 Progressive Decision Table"
dialect "mvel"
$sc : ShoppingCart( totalPrice >= 80000.0B )
modify( $sc ) {
setDiscount( 0.15B )
//from row number: 2
rule "Row 2 Progressive Decision Table"
dialect "mvel"
$sc : ShoppingCart( totalPrice >= 50000.0B , totalPrice < 80000.0B )
modify( $sc ) {
setDiscount( 0.12B )
//from row number: 3
rule "Row 3 Progressive Decision Table"
dialect "mvel"
$sc : ShoppingCart( totalPrice >= 10000.0B , totalPrice < 50000.0B )
modify( $sc ) {
setDiscount( 0.10B )
//from row number: 4
rule "Row 4 Progressive Decision Table"
dialect "mvel"
$sc : ShoppingCart( totalPrice < 10000B )
modify( $sc ) {
setDiscount( 0B )
A stateless session can be called like a function passing it some data and then receiving some results back. Some common use cases for stateless sessions are, but not limited to:
Stateful Sessions are long lived and allow iterative changes over time. Some common use cases for Stateful Sessions are, but not limited to:
The kmodule.xml file is the descriptor that selects resources to knowledge bases and configures those knowledge bases and sessions.
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="kbase1">
<ksession name="ksession1"/>
</kbase>
<kbase name="kbase2" packages="org.some.pkg">
<ksession name="ksession2"/>
</kbase>
<kbase name="kbase3" includes="kbase2" packages="org.some.pkg2">
<ksession name="ksession3"/>
</kbase>
<kbase name="kbase4" packages="org.some.pkg, org.other.pkg">
<ksession name="ksession4"/>
</kbase>
<kbase name="kbase5" packages="org.*">
<ksession name="ksession5"/>
</kbase>
<kbase name="kbase6" packages="org.some.*">
<ksession name="ksession6"/>
</kbase>
</kmodule>
*'kbase1' includes all resources from the KieModule.
docker run -p 8080:8080 -p 8001:8001 -d --name drools-workbench jboss/drools-workbench-showcase:latest
docker run -p 8180:8080 -d --name kie-server --link drools-wb:kie-wb jboss/kie-server-showcase:latest
when the workbench and kie-server are both started correctly, the kie server will be in the server list of workbench
The base URL for these will remain as the endpoint defined earlier (for example: http://SERVER:PORT/CONTEXT/services/rest/server/ )
Returns the Execution Server information
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="Kie Server info">
<kie-server-info>
<capabilities>KieServer</capabilities>
<capabilities>BRM</capabilities>
<capabilities>BPM</capabilities>
<capabilities>CaseMgmt</capabilities>
<capabilities>BPM-UI</capabilities>
<capabilities>BRP</capabilities>
<capabilities>DMN</capabilities>
<capabilities>Swagger</capabilities>
<location>http://172.17.0.3:8080/kie-server/services/rest/server</location>
<messages>
<content>Server KieServerInfo{serverId='kie-server-e65b93b4c4f8', version='7.14.0.Final', name='kie-server-e65b93b4c4f8', location='http://172.17.0.3:8080/kie-server/services/rest/server', capabilities=[KieServer, BRM, BPM, CaseMgmt, BPM-UI, BRP, DMN, Swagger], messages=null}started successfully at Mon Nov 26 03:07:30 UTC 2018</content>
<severity>INFO</severity>
<timestamp>2018-11-26T03:07:30.931Z</timestamp>
</messages>
<name>kie-server-e65b93b4c4f8</name>
<id>kie-server-e65b93b4c4f8</id>
<version>7.14.0.Final</version>
</kie-server-info>
</response>
Using POST HTTP method, you can execute various commands on the Execution Server. E.g: create-container, list-containers, dispose-container and call-container.
CreateContainerCommand
GetServerInfoCommand
ListContainersCommand
CallContainerCommand
DisposeContainerCommand
GetContainerInfoCommand
GetScannerInfoCommand
UpdateScannerCommand
UpdateReleaseIdCommand
The commands itself can be found in the org.kie.server.api.commands package.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="List of created containers">
<kie-containers>
<kie-container container-alias="ebiz" container-id="ebiz_1.0.0" status="STARTED">
<config-items>
<itemName>KBase</itemName>
<itemValue></itemValue>
<itemType>BPM</itemType>
</config-items>
<config-items>
<itemName>KSession</itemName>
<itemValue></itemValue>
<itemType>BPM</itemType>
</config-items>
<config-items>
<itemName>MergeMode</itemName>
<itemValue>MERGE_COLLECTIONS</itemValue>
<itemType>BPM</itemType>
</config-items>
<config-items>
<itemName>RuntimeStrategy</itemName>
<itemValue>SINGLETON</itemValue>
<itemType>BPM</itemType>
</config-items>
<messages>
<content>Container ebiz_1.0.0 successfully created with module com.freshal:ebiz:1.0.1.</content>
<severity>INFO</severity>
<timestamp>2018-11-26T03:07:35.243Z</timestamp>
</messages>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</release-id>
<resolved-release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</resolved-release-id>
<scanner status="DISPOSED"/>
</kie-container>
</kie-containers>
</response>
Returns the status and information about a particular container. For example, executing http://SERVER:PORT/CONTEXT/services/rest/server/containers/MyProjectContainer could return the following example container info.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response type="SUCCESS" msg="Info for container ebiz_1.0.0">
<kie-container container-alias="ebiz" container-id="ebiz_1.0.0" status="STARTED">
<config-items>
<itemName>KBase</itemName>
<itemValue></itemValue>
<itemType>BPM</itemType>
</config-items>
<config-items>
<itemName>KSession</itemName>
<itemValue></itemValue>
<itemType>BPM</itemType>
</config-items>
<config-items>
<itemName>MergeMode</itemName>
<itemValue>MERGE_COLLECTIONS</itemValue>
<itemType>BPM</itemType>
</config-items>
<config-items>
<itemName>RuntimeStrategy</itemName>
<itemValue>SINGLETON</itemValue>
<itemType>BPM</itemType>
</config-items>
<messages>
<content>Container ebiz_1.0.0 successfully created with module com.freshal:ebiz:1.0.1.</content>
<severity>INFO</severity>
<timestamp>2018-11-26T03:07:35.243Z</timestamp>
</messages>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</release-id>
<resolved-release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</resolved-release-id>
<scanner status="DISPOSED"/>
</kie-container>
</response>
Allows you to create a new Container in the Execution Server. For example, to create a Container with the id of MyRESTContainer the complete endpoint will be: http://SERVER:PORT/CONTEXT/services/rest/server/containers/MyRESTContainer. Example Request to create a container
<kie-container container-id="MyRESTContainer">
<release-id>
<artifact-id>Project1</artifact-id>
<group-id>com.redhat</group-id>
<version>1.0</version>
</release-id>
</kie-container>
Disposes the Container specified by the id. For example, executing http://SERVER:PORT/CONTEXT/services/rest/server/containers/MyProjectContainer using the DELETE HTTP method will return the following server response:
<response type="SUCCESS" msg="Container MyProjectContainer successfully disposed."/>
Executes operations and commands against the specified Container. You can send commands to this Container in the body of the POST request. For example, to fire all rules for Container with id MyRESTContainer (http://SERVER:PORT/CONTEXT/services/rest/server/containers/instances/MyRESTContainer), you would send the fire-all-rules command to it as shown below (in the body of the POST request):
<fire-all-rules/>
Following is the list of supported commands:
Returns the full release id for the Container specified by the id.
Allows you to update the release id of the container deployment. Send the new complete release id to the Server.
Returns information about the scanner for this Container’s automatic updates.
Allows you to start or stop a scanner that controls polling for updated Container deployments. To start the scanner, send a request similar to: http://SERVER:PORT/CONTEXT/services/rest/server/containers/{container-id}/scanner with the following POST data.
request body:
{
"lookup": null,
"commands":[
"insert": {
"object": {
"com.freshal.ebiz.Cart":{
"totalPrice": "10001.00"
"return-object":true,
"out-identifier": "cart"
"fire-all-rules":{}
response
{
"type" : "SUCCESS",
"msg" : "Container ebiz_1.0.0 successfully called.",
"result" : {
"execution-results" : {
"results" : [ {
"value" : {"com.freshal.ebiz.Cart":{
"totalPrice" : 10001.00,
"discount" : 0.9
}},
"key" : "cart"
} ],
"facts" : [ {
"value" : {"org.drools.core.common.DefaultFactHandle":{
"external-form" : "0:2:1389560427:1389560427:2:DEFAULT:NON_TRAIT:com.freshal.ebiz.Cart"
}},
"key" : "cart"
or use curl command to test
curl -X POST -H 'Content-type: application/json' -u 'kieserver:kieserver1!' --data @data.json http://localhost:8180/kie-server/services/rest/server/containers/instances/ebiz_1.0.0
some docs said that the command should be sent with
X-KIE-ContentType:JSON
,but it seems just using -H 'Content-type: application/json' is ok .
indeed, access the kie web(workbench)
http://localhost:8080/drools-wb/rest/controller
Returns a list of Kie Server templates
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<server-template-list>
<server-template>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
<container-specs>
<container-id>ebiz_1.0.1</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.0</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-specs>
<container-specs>
<container-id>ebiz_1.0.0</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-specs>
<configs/>
<server-instances>
<server-instance-id>[email protected]:8080</server-instance-id>
<server-name>[email protected]:8080</server-name>
<server-template-id>kie-server-e65b93b4c4f8</server-template-id>
<server-url>http://172.17.0.3:8080/kie-server/services/rest/server</server-url>
</server-instances>
<capabilities>RULE</capabilities>
<capabilities>PROCESS</capabilities>
<capabilities>PLANNING</capabilities>
</server-template>
</server-template-list>
Returns a Kie Server template
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<server-template-details>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
<container-specs>
<container-id>ebiz_1.0.1</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.0</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-specs>
<container-specs>
<container-id>ebiz_1.0.0</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-specs>
<configs/>
<server-instances>
<server-instance-id>[email protected]:8080</server-instance-id>
<server-name>[email protected]:8080</server-name>
<server-template-id>kie-server-e65b93b4c4f8</server-template-id>
<server-url>http://172.17.0.3:8080/kie-server/services/rest/server</server-url>
</server-instances>
<capabilities>RULE</capabilities>
<capabilities>PROCESS</capabilities>
<capabilities>PLANNING</capabilities>
</server-template-details>
Creates a new Kie Server template with the specified id
Example Request to create a new Kie Server template
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<server-template-details>
<server-id>test-demo</server-id>
<server-name>test-demo</server-name>
<configs/>
<capabilities>RULE</capabilities>
<capabilities>PROCESS</capabilities>
<capabilities>PLANNING</capabilities>
</server-template-details>
Deletes a Kie Server template with the specified id
Returns all containers on given server
localhost:8080/drools-wb/rest/controller/management/servers/kie-server-e65b93b4c4f8/containers
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<container-spec-list>
<container-spec>
<container-id>ebiz_1.0.1</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.0</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-spec>
<container-spec>
<container-id>ebiz_1.0.0</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-spec>
</container-spec-list>
Returns the Container information including its release id and configuration
localhost:8080/drools-wb/rest/controller/management/servers/kie-server-e65b93b4c4f8/containers/ebiz_1.0.0
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<container-spec-details>
<container-id>ebiz_1.0.0</container-id>
<container-name>ebiz</container-name>
<server-template-key>
<server-id>kie-server-e65b93b4c4f8</server-id>
<server-name>kie-server-e65b93b4c4f8</server-name>
</server-template-key>
<release-id>
<artifact-id>ebiz</artifact-id>
<group-id>com.freshal</group-id>
<version>1.0.1</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<runtimeStrategy>SINGLETON</runtimeStrategy>
<kbase></kbase>
<ksession></ksession>
<mergeMode>MERGE_COLLECTIONS</mergeMode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scannerStatus>STOPPED</scannerStatus>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-spec-details>
Creates a new Container with the specified containerId and the given release id and optionally configuration Example Server Request:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<container-spec-details>
<container-id>hr</container-id>
<container-name>hr</container-name>
<server-template-key>
<server-id>demo</server-id>
</server-template-key>
<release-id>
<artifact-id>HR</artifact-id>
<group-id>org.jbpm</group-id>
<version>1.0</version>
</release-id>
<configs>
<entry>
<key>PROCESS</key>
<value xsi:type="processConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<strategy>Singleton</strategy>
<kie-base-name></kie-base-name>
<kie-session-name></kie-session-name>
<merge-mode>Merge Collections</merge-mode>
</value>
</entry>
<entry>
<key>RULE</key>
<value xsi:type="ruleConfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<scanner-status>STOPPED</scanner-status>
</value>
</entry>
</configs>
<status>STARTED</status>
</container-spec-details
Disposes a Container with the specified containerId
Starts the Container. No request body required
Stops the Container. No request body required
Drools Runtime KIE API简介