我是Kie Workbench的新手。我正在使用Java Rest调用在kie工作台中触发规则。请在下面找到代码:

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对象的目的?

请注意,我只有一个使用了这一事实的决策表。

最佳答案

在搜索了不同的博客和用户论坛后,得到了一个很好的解决方案。上述问题可以通过以下步骤解决:

1)使用“ adapterRule”而不是“ get-adapter”来获取结果。

2)在KIE Workbench中,搜索部署描述符并进行以下更改:
<runtime-strategy>PER_REQUEST</runtime-strategy>
默认情况下,运行时策略为SINGLETON。

希望这有道理并能帮助别人。

关于java - Kie Workbench从 session 中删除现有事实,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39763208/

10-09 05:46