我是Kie Workbench的新手。我正在使用Java Rest调用在kie workbench中触发规则。请找到以下代码:
public class RuleEngineConnector {
@Value("${brms.execution.server.url}")
private String SERVER_URL;
@Value("${brms.execution.server.username}")
private String USER;
@Value("${brms.execution.server.password}")
private String PASSWORD;
@Value("${brms.containerId}")
private String CONTAINER_ID;
private static final MarshallingFormat FORMAT = MarshallingFormat.JAXB;
public String getAdapter(AdapterRuleDO adapterRule) {
KieServicesConfiguration cfg = KieServicesFactory.newRestConfiguration(SERVER_URL, USER, PASSWORD);
cfg.setMarshallingFormat(FORMAT);
Set<Class<?>> extraClasses = new HashSet<Class<?>>();
extraClasses.add(AdapterRuleDO.class);
cfg.addJaxbClasses(extraClasses);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(cfg);
ServiceResponse<ExecutionResults> response = getRulesResponse(adapterRule, kieServicesClient);
List<AdapterRuleDO> listOfObjects = (List<AdapterRuleDO>) response.getResult().getValue("get-adapter");//to be changed
return listOfObjects.get(0).getAdapterName();
}
private ServiceResponse<ExecutionResults> getRulesResponse(AdapterRuleDO adapterRule, KieServicesClient kieServicesClient) {
List<Command<?>> commands = new ArrayList<Command<?>>();
KieCommands commandsFactory = KieServices.Factory.get().getCommands();
commands.add(commandsFactory.newInsert(adapterRule, "adapterRule"));
commands.add(commandsFactory.newFireAllRules());
commands.add(commandsFactory.newGetObjects("get-adapter"));
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands);
RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
ServiceResponse<ExecutionResults> response = ruleServicesClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
return response;
}
}
我正在获取正确的规则,并在触发规则后在AdapterRuleDO类中正确更新值。一个问题是,当我再次调用此方法第二次执行规则时,我收到两个AdapterRuleDO对象,并且对于每个后续调用,我得到一个额外的对象。似乎会话中的对象已存储,并且不会为每次调用清除。如何为每次调用实现这一点,我将只得到一个AdapterRuleDO对象?
请注意我只有一个这样的决策表,其中使用了这个事实。
答案 0 :(得分:1)
搜索不同的博客后,用户论坛得到的解决方案运行良好。上述问题可以通过以下步骤解决:
1)使用“adapterRule”获取结果而不是“get-adapter”。
2)在KIE Workbench中,搜索部署描述符并进行以下更改:
bufio.Scanner
默认情况下,运行时策略为SINGLETON。
希望这有意义并帮助别人。
答案 1 :(得分:0)
如果您对无状态评估感兴趣,请尝试将会话配置为无状态。这将为每个请求创建一个新会话。 您应该可以在kie-workbench中执行此操作。
希望它有所帮助,
答案 2 :(得分:0)
代替以下行:
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands);
使用这一行:
BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands,Ksession_name);