[英]Fire rules on drools workbench from java application
This seems to be a popular question around drools... 这似乎是流口水的一个流行问题。
I've created some rules on drools workbench and a simple java application to communicate with it. 我在drools工作台上创建了一些规则,并创建了一个与之通信的简单Java应用程序。
I'm able to connect to the workbench (authentication and so on), I can retrieve the names from the set of rules but my "fireAllRules()" instruction returns zero and has no impact on my object. 我能够连接到工作台(身份验证等),我可以从规则集中检索名称,但是我的“ fireAllRules()”指令返回零,并且对我的对象没有影响。
However, when I add the exact same rules locally (.drl file) it runs smoothly and the result is correct. 但是,当我在本地添加完全相同的规则(.drl文件)时,它运行平稳,结果正确。
Any ideas? 有任何想法吗?
Rule (both on workbench and local): 规则(在工作台和本地):
package org1.notif;
rule "validate"
dialect "mvel"
when
c : Communication( status == "Pending" , type == "Dual" )
then
modify( c ) {
setStatus( "Executed" )
}
end
Java code (for communicating with Workbench): Java代码(用于与Workbench通信):
public static final void main(String[] args) {
try {
KieServices ks = KieServices.Factory.get();
KieResources resources = ks.getResources();
String url = "http://192.168.9.20:8080/drools-wb/maven2/org1/notif/1.0/notif-1.0.jar";
UrlResource urlResource = (UrlResource) resources.newUrlResource(url);
urlResource.setUsername("admin");
urlResource.setPassword("admin");
urlResource.setBasicAuthentication("enabled");
InputStream stream = urlResource.getInputStream();
KieRepository repo = ks.getRepository();
KieModule k = repo.addKieModule(resources.newInputStreamResource(stream));
KieContainer kc = ks.newKieContainer(k.getReleaseId());
KieBase kBase = kc.getKieBase();
System.out.println(kBase.getKiePackage("org1.notif").getRules());
KieSession kSession = kBase.newKieSession();
Communication c = new Communication();
c.setStatus("Pending");
c.setType("Dual");
kSession.insert(c);
System.out.println(kSession.fireAllRules());
System.out.println(c.getStatus());
kSession.dispose();
}
(...)
The problem is in the following statement System.out.println(kSession.fireAllRules());
问题出在以下语句
System.out.println(kSession.fireAllRules());
In order for it to work, the "fireAllRules" instruction must not be inside the println method. 为了使其正常运行,“ fireAllRules”指令一定不能位于println方法内。 Rookie mistake
新秀错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.