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

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





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值