标签:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>os.nut.drools</groupId> <artifactId>drools-training</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <drools.version>6.3.0.Final</drools.version> </properties> <repositories> <repository> <id>guvnor-m2-repo</id> <name>Guvnor M2 Repo</name> <url>http://192.168.0.101:8080/kie-drools/maven2/</url> </repository> </repositories> <dependencies> <!-- drools --> <dependency> <groupId>org.kie</groupId> <artifactId>kie-api</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-core</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-compiler</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-decisiontables</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-templates</artifactId> <version>${drools.version}</version> </dependency> <dependency> <groupId>org.kie</groupId> <artifactId>kie-ci</artifactId> <version>${drools.version}</version> </dependency> <!-- test --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> </dependencies> </project>
package org.sky.drools.approvaldecision; import java.io.InputStream; import org.drools.compiler.kproject.ReleaseIdImpl; import org.drools.core.io.impl.UrlResource; import org.kie.api.KieServices; import org.kie.api.builder.KieModule; import org.kie.api.builder.KieRepository; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.StatelessKieSession; public class RemotePaymentRulz { public static void main(String[] args) throws Exception { String url = "http://192.168.0.101:8080/kie-drools/maven2/org/sky/drools/ApprovalDecision/1.0.0/ApprovalDecision-1.0.0.jar"; ReleaseIdImpl releaseId = new ReleaseIdImpl("org.sky。drools", "ApprovalDecision", "LATEST"); KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); UrlResource urlResource = (UrlResource) ks.getResources().newUrlResource(url); urlResource.setUsername("tomcat"); urlResource.setPassword("tomcat"); urlResource.setBasicAuthentication("enabled"); InputStream is = urlResource.getInputStream(); KieModule kModule = kr.addKieModule(ks.getResources().newInputStreamResource(is)); KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId()); StatelessKieSession kSession = kContainer.newStatelessKieSession("defaultStatelessKieSession"); PaymentInfo m = new PaymentInfo(); m.setMoneyAmount(5001); kSession.execute(m); System.out.println(m.getDecisionPath()); if (m.getDecisionPath().equalsIgnoreCase("m")) { System.out.println("数额<=5000需要经理审批"); } else { System.out.println("数额>5000需要总经理审批"); } } }
String url = "http://192.168.0.101:8080/kie-drools/maven2/org/sky/drools/ApprovalDecision/1.0.0/ApprovalDecision-1.0.0.jar"; KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); UrlResource urlResource = (UrlResource) ks.getResources().newUrlResource(url);
urlResource.setUsername("tomcat"); urlResource.setPassword("tomcat"); urlResource.setBasicAuthentication("enabled"); InputStream is = urlResource.getInputStream(); KieModule kModule = kr.addKieModule(ks.getResources().newInputStreamResource(is)); KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
StatelessKieSession kSession = kContainer.newStatelessKieSession("defaultStatelessKieSession"); PaymentInfo m = new PaymentInfo(); m.setMoneyAmount(5001); kSession.execute(m); System.out.println(m.getDecisionPath()); if (m.getDecisionPath().equalsIgnoreCase("m")) { System.out.println("数额<=5000需要经理审批"); } else { System.out.println("数额>5000需要总经理审批"); }
jboss规则引擎KIE Drools 6.3.0 Final 教程(2)
标签:
原文地址:http://blog.csdn.net/lifetragedy/article/details/51148779