caicongyang

记录与分享,让你我共成长!

kie-server java client json for drools6.4

1.前置条件:

搭建kie-web + kie-server的drools规则引擎

2.KieServerClientTest.java

package com.caicongyang;

import java.util.LinkedList;
import java.util.List;

import org.kie.api.KieServices;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.server.api.marshalling.MarshallingFormat;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.client.KieServicesClient;
import org.kie.server.client.KieServicesConfiguration;
import org.kie.server.client.KieServicesFactory;
import org.kie.server.client.RuleServicesClient;

import com.ccy.com.ccy.drools.Person;

/**
 * 
 * 
 * @author caicongyang
 * @description 本例子为kie-server java client json 调用droos规则
 */
public class KieServerClientTest {

    private static String url        = "http://192.168.236.101:8080/kie-server/services/rest/server";
    private static String username   = "kieserver";
    private static String password   = "kieserver";
    private static String container  = "drools";
    private static String kieSession = "kiesession1";

    public static void main(String[] args) {
        //bean 路径必须与kie-web上的bean 路径包名字段完全相同
        Person person = new Person();
        person.setAge(11);
        person.setName("ccy");
        KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(url, username, password);
        config.setMarshallingFormat(MarshallingFormat.JSON);
        config.setTimeout(30000L);

        KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
        RuleServicesClient rules = client.getServicesClient(RuleServicesClient.class);

        KieCommands cmdFactory = KieServices.Factory.get().getCommands();

        List<Command<?>> commands = new LinkedList<Command<?>>();
        commands.add(cmdFactory.newInsert(person, "person"));
        commands.add(cmdFactory.newFireAllRules());
        ServiceResponse<org.kie.api.runtime.ExecutionResults> response = rules.executeCommandsWithResults(container,
            cmdFactory.newBatchExecution(commands, kieSession));

        System.out.println(response.getMsg());
        ExecutionResults result = response.getResult();
        person = (Person) result.getValue("person");
        System.out.println(person.getName());

    }
}


更多精彩内容请继续关注我的博客http://blog.csdn.net/caicongyang

记录与分享,你我共成长 -from caicongyang

如果你觉得本文对你有帮助,可以扫描下面的微信二维码,请我喝杯水咯!





阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。--caicongyang https://blog.csdn.net/caicongyang/article/details/52369143
个人分类: drools/wildfly
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

kie-server java client json for drools6.4

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭