【问题标题】:KIE Server execution using Java API使用 Java API 执行 KIE 服务器
【发布时间】:2021-11-30 17:02:26
【问题描述】:

我有简单的业务流程,在 RestService WorkItem 之前和之后执行规则 BPM Process

我还在设置中定义了 Rest Work Handler 定义。 Rest Work Handler DefinitionInstall Rest Work Item Handler.

使用 Java KIE A​​PI 调用 RuleServicesClient 来执行规则和 BPM 流程。

KieServices kieServices = KieServices.Factory.get();

        CredentialsProvider credentialsProvider = new EnteredCredentialsProvider(USERNAME, PASSWORD);

        KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration(KIE_SERVER_URL, credentialsProvider);

        // Set the Marshaling Format to JSON. Other options are JAXB and XSTREAM
        kieServicesConfig.setMarshallingFormat(MarshallingFormat.JSON);

        KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);

        // Retrieve the RuleServices Client.
        RuleServicesClient rulesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);

        List<Command<?>> commands = new ArrayList<>();

        KieCommands commandFactory = kieServices.getCommands();

        commands.add(commandFactory.newInsert(new RestFlowRequest(\"Sample\"), \"SampleRequest\"));

        commands.add(commandFactory.newStartProcess(\"RuleFlowSample.DecisionRestBPM\"));
        //commands.add(commandFactory.newFireAllRules(\"numberOfFiredRules\"));
        //ProcessServicesClient processService
        //        = kieServicesClient.getServicesClient(ProcessServicesClient.class);
        //processService.startProcess(CONTAINER_ID,\"RuleFlowSample.DecisionRestBPM\");

        BatchExecutionCommand batchExecutionCommand = commandFactory.newBatchExecution(commands);
        ServiceResponse<ExecutionResults> response = rulesClient.executeCommandsWithResults(CONTAINER_ID, batchExecutionCommand);

它无法执行 Rest Service 任务并出现以下错误 Error Thrown By KIE Server

如果更改代码以使用 ProcessServicesClient 启动流程,则业务流程执行没有任何问题,但规则不执行。

    标签: drools jbpm kie


    【解决方案1】:

    您正在使用正确的方法 commands.add(commandFactory.newStartProcess("RuleFlowSample.DecisionRestBPM"));"

    我使用下面的代码(https://github.com/jbossdemocentral/kie-server-client-examples/blob/master/src/main/java/com/redhat/demo/qlb/loan_application/Main.java)尝试了它,它工作正常:

    KieServices kieServices = KieServices.Factory.get();

        CredentialsProvider credentialsProvider = new EnteredCredentialsProvider(USERNAME, PASSWORD);
    
        KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration(KIE_SERVER_URL, credentialsProvider);
    
        // Set the Marshaling Format to JSON. Other options are JAXB and XSTREAM
        kieServicesConfig.setMarshallingFormat(MarshallingFormat.JSON);
    
        KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);
    
        // Retrieve the RuleServices Client.
        RuleServicesClient rulesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
    
        /*
         * Create the list of commands that we want to fire against the rule engine. In this case we insert 2 objects, applicant and loan,
         * and we trigger a ruleflow (with the StartProcess command).
         */
        List<Command<?>> commands = new ArrayList<>();
    
        KieCommands commandFactory = kieServices.getCommands();
        //The identifiers that we provide in the insert commands can later be used to retrieve the object from the response.
        commands.add(commandFactory.newInsert(getApplicant(), "applicant"));
        commands.add(commandFactory.newInsert(getLoan(), "loan"));
        commands.add(commandFactory.newStartProcess("loan-application.loan-application-decision-flow"));
    

    出于测试目的,请删除休息处理程序并尝试使用脚本任务并查看结果。

    【讨论】:

    • 演示需要 Rest Handler,看起来 WorkItemHandler 实现仅适用于 ProcessServicesClient
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 2020-04-01
    • 2017-11-23
    • 2016-07-24
    • 2020-05-18
    • 2016-03-24
    相关资源
    最近更新 更多