Drools 6.4 KieScanner:如何在Maven中创建和添加Jar规则? [英] Drools 6.4 KieScanner : How create and add Jar with rules in Maven?

查看:260
本文介绍了Drools 6.4 KieScanner:如何在Maven中创建和添加Jar规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Drools和Maven的初学者,我遇到了使用KieScanner加载规则的问题。



该项目的目的是能够动态加载永久性KieSession中的规则。我想知道是否可以使用KieFileSystem管理规则(不确定是否可以在没有处理会话并启动另一个会导致缺少先前插入的事实的情况下),但好的方法是使用KieScanner。



这似乎需要创建一个包含规则并具有Maven ID(ReleaseId)的Jar,但我找不到有关创建这些Jar文件的详细文档。



这样的罐子里应该包含哪些文件? DRL文件,Pom.xml和manifest.mf?



这个Jar文件可以添加到哪里?根据文档,当检测到该文件的新问题时,不应该在类路径中添加它:一旦模块在类路径上,就不能动态加载其他版本。



是否需要Maven命令?



有人可以向我提供有关这些点的信息,或者给我一个链接来创建和部署这样一个Jar及其描述了KieScanner中的管理?非常感谢。

解决方案

以下是无状态 kiesession 的示例使用来自maven存储库的 kjar (代码在scala中,但我相信你会明白你主要使用Java编程)



< pre class =lang-scala prettyprint-override> private val services = KieServices.Factory.get
private val releaseId = services.newReleaseId(com.piedpiper,demo, [1.0,2))
private val kieContainer = services.newKieContainer(releaseId)

val kScanner = services.newKieScanner(kieContainer)
kScanner.start(2000L)

val kieSession = kieContainer.newStatelessKieSession(SimpleSession)

@tailrec
def check(){
val(aName,aAge)= scala.io .StdIn.readf2({0} {1,number})
val applicant =申请人(name = aName.asInstanceOf [String],age = aAge.asInstanceOf [Long] .toInt,pass = false)
kieSession.execute(申请人)
println(s有效是$ {appl icant.pass})
check()
}

check()

这使用maven和gav com.piedpiper:demo:[1.0,2)查找一个kjar(iow来自<$ c的任何版本) $ c> 1.0 到 2 (不包括在内)。如果该范围内的新版本可用,则每两秒检查一次。



kjar 包含知识资源, kmodule.xml etc(使用 kie-maven-plugin 插件扩展名编译规则的正确kjar)。在这种情况下,它还包含事实模型(我通常会在不同的maven工件中将其分开。)



上面示例中使用的规则是

 规则有效年龄

$ a:申请人(年龄> 13,传递== false) )
然后
修改($ a){
pass = true
}
结束

将规则更改为例如> 15 ,需要2秒才能投入使用。


I am a beginner with Drools and Maven and I am facing a problem to load rules with KieScanner.

The aim of the project is to be able to dynamically load rules in a permanent KieSession. I wonder if it is possible to manage rules with the KieFileSystem (not sure it is possible without a dispose of the session and starting another one leading to the lack of the previous inserted facts), but the good way is to use KieScanner.

It seems this requires the creation of a Jar containing the rules and having a Maven ID (ReleaseId), but I could not find detailed documentation about creation of these Jar files.

Which files shall be included in such a Jar ? DRL files, Pom.xml and manifest.mf ?

Where can this Jar file be added ? According to documentation it should not be added in the classpath when the detection of new issues of that file is necessary : "once a module is on the classpath, no other version may be loaded dynamically".

Is a Maven command needed ?

Can someone give me information on those points or give me a link where creation and deployment of such a Jar and its management in a KieScanner is described ? Thanks a lot.

解决方案

Here is an example of a stateless kiesession using a kjar from a maven repository (code is in scala, but i am sure you'll get the idea of you primarily program in Java)

private val services = KieServices.Factory.get
private val releaseId = services.newReleaseId("com.piedpiper", "demo", "[1.0,2)")
private val kieContainer = services.newKieContainer(releaseId)

val kScanner = services.newKieScanner(kieContainer)
kScanner.start(2000L)

val kieSession = kieContainer.newStatelessKieSession("SimpleSession")

@tailrec
def check() {
  val (aName, aAge) = scala.io.StdIn.readf2("{0} {1,number}")
  val applicant = Applicant(name = aName.asInstanceOf[String], age = aAge.asInstanceOf[Long].toInt, pass = false)
  kieSession.execute(applicant)
  println(s"valid is ${applicant.pass}")
  check()
}

check()

This looks for a kjar using maven with the gav com.piedpiper:demo:[1.0,2) (iow any version from 1.0 to 2 (non-inclusive). It checks every two seconds if a new version within that range is available.

The kjar contains the knowledge resources, the kmodule.xml etc (a proper kjar with the compiled rules using the kie-maven-plugin plugin-extension ). In this case it also contains the fact model (i would normally separate that out in a different maven artefact.)

The rule used in the example above is

rule "Is of valid age"
when
    $a : Applicant( age > 13, pass==false )
then
    modify($a){
        pass = true
    }
end

When changing the rule to for example > 15, it takes 2 seconds to become operational.

这篇关于Drools 6.4 KieScanner:如何在Maven中创建和添加Jar规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆