Drools 6:为正在运行的KieSession添加规则 [英] Drools 6: add rules to a running KieSession

查看:707
本文介绍了Drools 6:为正在运行的KieSession添加规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我无法找到最好的方法(意味着最小的开销)在Drools 6.0.0中向正在运行的KieSession添加规则并且仍然在KieSession中保存我的事实。在Drools 5中,当KBase被更改时,KSession被更新了,但是由于我的规则不是在KieBase中创建的,因此Drools 6似乎不同。有没有办法在不替换KieFileSystem中的整个KieModules或Jars的情况下完成它。我认为应该有一个简单的方法。



你们有个主意吗?



问候

解决方案

是的,支持用例,但重要的是要了解Drools 6引入了版本化可部署工件的概念( mavenized kjars)。换句话说,一旦你用版本X创建一个kjar,它应该是不可变的。如果要向kjar中定义的kbases添加/删除规则,则应创建另一个kjar版本X + 1。这个kjar可以在磁盘中作为真正的jar或在内存中创建。



理解kjar是不可变源工件和kcontainer的概念也很重要是实例化kjar并允许使用其kbases和ksessions的容器。



如果可以理解,那么您需要做的就是为X版实例化容器,当您想要更改kbase时,请调用容器updateToVersion(.. 。)将其更新为新版本的方法。 KBase和KSessions会像在Drools 5中一样逐步更新和保存。



此处的单元测试:https://github.com/droolsjbpm/drools/blob/master/drools-compiler/ src / test / java / org / drools / compiler / integrationtests / IncrementalCompilationTest.java#L158



代码段:

  //使用版本1.0.0 
ReleaseId releaseId1 = ks.newReleaseId(org.kie,test-upgrade,1.0.0 );
...

//创建会话和消防规则
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession ksession = kc.newKieSession();
ksession.insert(新消息(Hello World));
...

//升级到版本1.1.0
ReleaseId releaseId2 = ks.newReleaseId(org.kie,test-upgrade,1.1.0 );
kc.updateToVersion(releaseId2);

//继续使用会话
ksession.insert(新消息(Hello World));
...


till now I couldn't figure out the best way (meaning with minimal overhead) to add rules to a running KieSession in Drools 6.0.0 AND still keeping my facts in KieSession. In Drools 5 the KSession was updated when KBase was changed, but the same seems not be true for Drools 6 since my rules are not created in the KieBase. Is there a way to do it without replacing whole KieModules or Jars in the KieFileSystem. I think there should be an easy way to it.

Do you guys have an idea?

Regards

解决方案

Yes, the use case is supported, but it is important to understand that Drools 6 introduces the concept of versioned deployable artifacts (the mavenized kjars). In other words, once you create a kjar with version X, it is supposed to be immutable. If you want to add/remove rules to the kbases defined in kjar, you should create another kjar version X+1. This kjar can be created either physically in the disk as a real jar or in memory.

Also important to understand the concept that the kjar is the immutable source artifact and the kcontainer is the container that instantiates the kjar and allows the use of its kbases and ksessions.

If that is understood, then all you need to do is instantiate the container for version X, and when you want to change the kbase, call the container updateToVersion(...) method to update it to the new version. KBases and KSessions are incrementally updated and preserved like they were in Drools 5.

Unit test here: https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java#L158

Code snippet:

    // work with version 1.0.0
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    ...

    // Create a session and fire rules
    KieContainer kc = ks.newKieContainer( releaseId1 );
    KieSession ksession = kc.newKieSession();
    ksession.insert(new Message("Hello World"));
    ...

    // upgrade to version 1.1.0
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    kc.updateToVersion(releaseId2);

    // continue working with the session
    ksession.insert(new Message("Hello World"));
    ...

这篇关于Drools 6:为正在运行的KieSession添加规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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