drools - 使用rest调用规则服务时如何在json中分配规则流组
问题描述
我在使用规则流组定义的 brms7 中使用 rest 触发规则,我放置的 json 数据如下所示:
{
"commands": [
{
"insert": {
"object": {
"com.myspace.driver_department_traffic_violations.Violation": {
"speedLimit": 40,
"type": "Speed",
"actualSpeed": 55
}
}
}
},
{
"fire-all-rules": {}
},
{
"get-objects": {
"out-identifier": "violation"
}
},
{
"dispose": {}
}
]}
问题是如何在 json 数据中分配规则流组?服务器中的规则已分配规则流组,我需要在 json 中分配规则流组名称来触发规则。
提前谢谢了!
此致
解决方案
我知道这个问题已经存在了一段时间,所以我只是在这里抛出答案,以防有人来寻找答案。
对于我的示例,规则流组称为“事件”。
{
"lookup": "defaultKieSession",
"commands": [
{
"insert": {
"object": {
"com.myspace.driver_department_traffic_violations.Violation": {
"speedLimit": 40,
"type": "Speed",
"actualSpeed": 55
}
},
"out-identifier": "violation"
}
},
{
"set-focus": {
"name": "incident"
}
},
{
"fire-all-rules": {}
}
]
}
对于决策服务器上的远程执行,您的代码应如下所示:
List<Command<?>> commands = new ArrayList<>();
KieServices kieServices = KieServices.Factory.get();
KieCommands commandFactory = kieServices.getCommands();
commands.add(commandFactory.newAgendaGroupSetFocus("incident"));
如果您想知道,AgendaGroups 也会以同样的方式处理。您可以从文档中阅读关于 SO 的摘录。
推荐阅读
- permissions - 将自定义数据输入 GraphiQL Docs
- azure - ARM 模板,带有 Web 作业的 Web 应用服务
- python - 在 Python 中使用具有并发期货的互斥锁
- spring - SpringBootTest 与 Zuul 代理 - 空响应
- javascript - Angular 添加随机 JPG 图像?
- mysql - mysql nodejs连接太多
- visual-studio-code - 将 JavaCC 语法定义转换为 VSCode 语法高亮?
- r - 在 GitHub Actions .yaml 中为 R 包配置 codecov 令牌
- exec - 为什么 dows exec() 函数可以在原始代码中工作,但不能在 Python 3.7 中的函数或类中工作?
- angular-material - 角9更新后角材料损坏