我是drools和kie-server的新手。我遇到了如何通过激发规则RHS(然后是动作)在工作记忆中插入新事实然后通过这些动态插入事实激活其他规则的问题。
我期望当BaseFeature从外部插入工作内存并激活RuleOne时,在RuleOne中“然后”它将插入新的事实RuleResult,并期望激活RuleTwo,但它不会激活RuleTwo,只是RuleOne被激活了,这是我做错了吗?
这里我有两条规则和一套事实:
FACTS定义:
rule "RuleOne"
dialect "mvel"
salience 100
no-loop true
lock-on-active true
when
$b : BaseFeature( age < 22 || age > 40 )
then
RuleResult $r = new RuleResult();
$r.setRuleName( "RuleOne" );
$r.setState( false );
insertLogical( $r );
end
rule "RuleTwo"
dialect "mvel"
no-loop false
lock-on-active true
salience 10
when
$r : RuleResult( ruleName == "RuleOne" , state == false )
$a : AppResult( )
then
$a.setKey( "PASS" );
$a.setValue( "false" );
end
规则定义:
{
"lookup": "RuleChainTestStateless",
"commands": [
{
"insert": {
"return-object": false,
"object": {
"com.qf.rulechaintest.BaseFeature": {
"age": "10"
}
}
}
},
{
"insert": {
"return-object": true,
"out-identifier": "AppResult",
"object": {
"com.qf.rulechaintest.AppResult": {
}
}
}
},
{
"fire-all-rules": ""
},
{
"get-objects":{
"out-identifier":"allFactsInWrokingMemory"
}
}
]
}
如何实现fire-rules插入新事实并激发其他规则动态? 提前谢谢!
我正在使用kie-server(6.5 Final)进行测试,POST和Reponse如下:
POST:
{
"type": "SUCCESS",
"msg": "Container RuleChainTest1.1 successfully called.",
"result": {
"execution-results": {
"results": [
{
"key": "",
"value": 1
},
{
"key": "AppResult",
"value": {
"com.qf.rulechaintest.AppResult": {
"key": null,
"value": null
}
}
},
{
"key": "allFactsInWrokingMemory",
"value": [
{
"com.qf.rulechaintest.BaseFeature": {
"age": 10
}
},
{
"com.qf.rulechaintest.AppResult": {
"key": null,
"value": null
}
},
{
"com.qf.rulechaintest.RuleResult": {
"ruleName": "RuleOne",
"score": null,
"state": false
}
}
]
}
],
"facts": [
{
"key": "AppResult",
"value": {
"org.drools.core.common.DefaultFactHandle": {
"external-form": "0:2:1542374590:1542374590:2:DEFAULT:NON_TRAIT:com.qf.rulechaintest.AppResult"
}
}
}
]
}
}
}
REPONSE:
"com.qf.rulechaintest.AppResult": {
"key": null,
"value": null
}
请注意响应:
"com.qf.rulechaintest.AppResult": {
"key": "PASS",
"value": "false"
}
预计会是什么:
{{1}}
答案 0 :(得分:0)
如果您不了解这些规则属性的用途,请阅读文档。然后,我想,你会意识到你可以删除它们。
salience 100 or 10
no-loop true or false
lock-on-active true
答案 1 :(得分:0)
我同意laune你应该阅读规则属性的含义(参见文档[1]中的内容)。我认为这是因为你对规则有锁定活动。请查看我链接的文档。
[1] https://docs.jboss.org/drools/release/6.5.0.Final/drools-docs/html/ch08.html#d0e9196
答案 2 :(得分:0)
尝试使用更新功能 “
然后
RuleResult $r = new RuleResult();
$r.setRuleName( "RuleOne" );
$r.setState( false );
update ( $r );
“