drools - 如何验证 drools 规则中的哪个条件失败?
问题描述
我正在使用 drools 7.44 并且有一个包含 20 多个规则的包。目前我面临的问题是有时我希望触发的某些规则没有触发。在then我可以添加日志语句,但不能在when中。有没有办法调试或记录规则的哪些条件失败?
如果客户年龄=21,性别=男性,则使用以下规则。我如何在运行时确定性别是导致规则不触发的标准。
rule "some rule"
when
$c : Customer(age>18 , gender == "female" )
then
........
do something here
log.debug("something to log")
end
这是一个简单的例子来说明问题。理想情况下,我们有多个条件。
解决方案
Use the DebugAgendaEventListener
to trace the rules evaluation. See the manual
This will cover only the case when the match succeeds. If not, nothing will be evaluated. There's a JIRA to track such failed evaluation
Extract from the manual
The Drools engine also supports the following agenda and working memory event listeners for debug logging:
DebugAgendaEventListener
DebugRuleRuntimeEventListener
These event listeners implement the same supported event-listener methods and include a debug print statement by default. You can add a specific supported event to be monitored and documented, or monitor all agenda or working memory activity.
For example, the following code uses the DebugRuleRuntimeEventListener event listener to monitor and print all working memory events:
Example code to monitor and print all working memory events
ksession.addEventListener( new DebugRuleRuntimeEventListener() );
推荐阅读
- python - Python 上的指数衰减曲线拟合。错误:优化警告
- node.js - 在 Node.js 中执行图像压缩后,无法从前端获取图像 URL
- php - Pulling random object out of array of objects
- angular - 如何在登陆时默认打开带有孩子的完整树?
- javascript - Material-UI 多表折叠/展开
- node.js - 使用 readline-sync 问题时 Node REPL 意外退出
- plsql - PL SQL 删除非 Ascii 字符,但不删除回车符
- javascript - 如何在 JQuery 中将 outerHTML 作为字符串返回?
- ios - 无法将简单的“yyyy:MM:dd HH:mm:ss”转换为日期对象。任何解决方案
- sorting - Kotlin while 循环不适用于三个条件