jBPM 6 中底层架构基于 Maven,所以我们可以很容易的进行 Maven jBPM 6 集成示例,本文分三个部分:
如下图
如图所示,我们有两台服务器,jBPM 6 服务器和客户端服务器:
Maven jBPM 6集成实际上就简化为 Maven settings.xml的配置问题。如下配置
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> <server> <id>guvnor-m2-repo</id> <username>admin</username> <password>password1!</password> <configuration> <wagonProvider>httpclient</wagonProvider> <httpConfiguration> <all> <usePreemptive>true</usePreemptive> </all> </httpConfiguration> </configuration> </server> </servers> <profiles> <profile> <id>guvnor-m2-repo</id> <repositories> <repository> <id>guvnor-m2-repo</id> <name>BRMS Repository</name> <url>http://10.66.218.46:8080/business-central/maven2/</url> <layout>default</layout> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>guvnor-m2-repo</activeProfile> </activeProfiles> </settings>
KieServices kServices = KieServices.Factory.get(); ReleaseId releaseId = kServices.newReleaseId( "com.redhat.gss", "01081954", "1.1-SNAPSHOT" ); KieContainer kContainer = kServices.newKieContainer( releaseId ); KieBase kbase = kContainer.getKieBase(); KieSession ksession = kbase.newKieSession();
借助于 Maven 的特性,KieScanner 可以周期性的扫描远程jBPM 6 服务器运行的Maven Repo,当有远程发布有变更时,KieScanner 会自动更新 KieRepository,使其为最新的发布,如下代码
KieServices kServices = KieServices.Factory.get(); ReleaseId releaseId = kServices.newReleaseId( "org.kie.example", "project1", "1.0.0-SNAPSHOT" ); KieContainer kContainer = kServices.newKieContainer( releaseId ); KieScanner kScanner = kServices.newKieScanner( kContainer ); kScanner.start( 1000 * 10); while(true) { KieSession ksession = kContainer.newKieSession(); ksession.fireAllRules(); Thread.sleep(10000); }