快速指南:剖析JBoss BPM跨进程通信
(文章來賓與北美紅帽公司高級解決方案架構師杰伊·保拉杰共同撰寫)
幾周的提示與技巧文章將深入探討JBoss BPM Suite,特別是有關如何在兩個流程之間進行通信的問題。 在進入解決方案詳細信息之前,讓我們首先約束將要討論的用例。
關于兩個進程之間的通信方式可能會有很多解釋,但是我們將從這里開始,以一種簡單的方式讓一個進程調用另一個進程。 我們還將通過提供的RestAPI展示這種簡單用法,我們將利用該API提供可部署的工件,您可以將其用作任何BPM流程中的自定義工作處理程序。
該工件是一個我們標記為RestApi.java的類,它包含設置和詳細信息,使您可以從現有過程中啟動另一個過程。
在本文結尾處,我們提供了完整的課程,但首先,我們仔細研究了各個活動部分。
每個類的頂部包括將要使用的各種導入的對象或類,我們對“知識就是一切”(KIE)API組件最感興趣,您會在其中找到它們以及代表我們的醫療保健示例領域模型的一些對象。
package org.jboss.demo.heathcare;import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;// JBoss BPM Suite API import org.kie.api.runtime.KieSession; import org.kie.api.runtime.manager.RuntimeEngine; import org.kie.api.runtime.process.ProcessInstance; import org.kie.services.client.api.RemoteRestRuntimeEngineFactory;// Domain model. import com.redhat.healthcare.CaseContext; import com.redhat.healthcare.Doctor; import com.redhat.healthcare.PatientInfo; import com.redhat.healthcare.Prescription; import com.redhat.healthcare.Rxdetail;接下來,我們將找到RestAPI類的實際開始,我們在其中設置使用API??所需的一些屬性以及一個構造函數,以確保JBoss BPM Suite服務器正在運行。 請注意,流程部署ID以及用戶名和密碼都是虛構的,因此與實際流程數據的任何相似之處都是偶然的。
String deploymentId = "com.redhat.healthcare:patients:1.0"; String bpmUrl = "http://localhost:8080/business-central"; String userId = "admin"; String password = "bpmsuite1!"; URL deploymentUrl;// Constructor to check for availability of BPM server. // public RestApi() {super();try {this.deploymentUrl = new URL();} catch (MalformedURLException e) {e.printStackTrace();} }測試的URL假定是基本的默認本地安裝,因此,如果您的安裝使用其他設置,則需要對此進行調整。
下一個代碼片段重點介紹了一種核心幫助程序方法,該方法為我們提供了對運行時引擎的引用。 這是通過RestAPI將我們綁定到特定部署com.redhat.healthcare:Patients:1.0的引擎,使我們可以啟動該部署中的流程。
// Get a runtime engine based on RestAPI and our deployment. // public RuntimeEngine getRuntimeEngine() {RemoteRestRuntimeEngineFactory restSessionFactory = new RemoteRestRuntimeEngineFactory(deploymentId, deploymentUrl, userId, password);// create REST requestRuntimeEngine engine = restSessionFactory.newRuntimeEngine();return engine; }有了運行時引擎,我們現在可以訪問和創建會話,然后我們就可以在其中啟動流程實例。
調用以下方法來啟動流程實例,并且僅出于清楚起見,該方法包含創建要提交到我們的流程中的數據集合。 您應該很容易看到可以根據需要將其抽象出來,以便將過程變量映射到您的類中。
// Setup our session, fill the data needed for process // instances and starting our process. // public void startProcess() {String taskUserId = userId;// create REST request.RuntimeEngine engine = getRuntimeEngine();KieSession ksession = engine.getKieSession();// setup data for submission to process instance.Doctor doctor = new Doctor();doctor.setAddress("3018 winter");doctor.setCity("madison");doctor.setGender("M");doctor.setGroupId("UW1001");doctor.setHospital("1001");doctor.setName("jey");doctor.setState("WI");PatientInfo pat = new PatientInfo();pat.setAge(12);pat.setName("jey");pat.setSymbtom("Diabetes Insipidus");pat.setType("Diabetes");Rxdetail rxdetail = new Rxdetail();List<rxdetail> details = new ArrayList<rxdetail>();rxdetail.setDrugName("xx");rxdetail.setOther("red");rxdetail.setQty(11);rxdetail.setRxNum(11);details.add(rxdetail);CaseContext cont = new CaseContext();cont.setApprovalReq("N");cont.setApprovalReq("Supervisor");Prescription prescription = new Prescription();prescription.setDoctor(doctor);prescription.setPatientInfo(pat);prescription.setRxdetails(details);// collect all data in our map.Map<string object=""> params = new HashMap<string object="">();params.put("prescription", prescription);params.put("caseContext", cont);// start process.ProcessInstance processInstance = ksession.startProcess("healthcare.patientCaseProcess", params);// verify process started.System.out.println("process id " + processInstance.getProcessId());System.out.println("process id " + processInstance.getId()); }通過這種方法,我們可以設置流程所需的醫生,患者和其他醫療詳細信息,將它們收集到地圖中,然后將其提交給流程實例以將其全部啟動。
現在,我們可以將所有這些聯系在一起,以便在調用此方法時運行的主類將設置我們的RestAPI,并在每次調用它時啟動一個新的流程實例。
// Start our process by using RestAPI. // public static void main(String[] ar) {RestApi api = new RestApi();api.startProcess(); }我們希望通過本醫學示例的簡單介紹可以使您了解如何利用提供的JBoss BPM Suite RestAPI來發揮自己的優勢。 在這種情況下,我們將其用于與BPM服務器上部署的任何其他進程與特定部署中的特定進程進行通信。
這是RestApi類:
package org.jboss.demo.heathcare;import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;// JBoss BPM Suite API import org.kie.api.runtime.KieSession; import org.kie.api.runtime.manager.RuntimeEngine; import org.kie.api.runtime.process.ProcessInstance; import org.kie.services.client.api.RemoteRestRuntimeEngineFactory;// Domain model. import com.redhat.healthcare.CaseContext; import com.redhat.healthcare.Doctor; import com.redhat.healthcare.PatientInfo; import com.redhat.healthcare.Prescription; import com.redhat.healthcare.Rxdetail;String deploymentId = "com.redhat.healthcare:patients:1.0"; String bpmUrl = "http://localhost:8080/business-central"; String userId = "admin"; String password = "bpmsuite1!"; URL deploymentUrl;// Constructor to check for availability of BPM server. // public RestApi() {super();try {this.deploymentUrl = new URL();} catch (MalformedURLException e) {e.printStackTrace();} }// Get a runtime engine based on RestAPI and our deployment. // public RuntimeEngine getRuntimeEngine() {RemoteRestRuntimeEngineFactory restSessionFactory = new RemoteRestRuntimeEngineFactory(deploymentId, deploymentUrl, userId, password);// create REST requestRuntimeEngine engine = restSessionFactory.newRuntimeEngine();return engine; }// Setup our session, fill the data needed for process // instances and starting our process. // public void startProcess() {String taskUserId = userId;// create REST request.RuntimeEngine engine = getRuntimeEngine();KieSession ksession = engine.getKieSession();// setup data for submission to process instance.Doctor doctor = new Doctor();doctor.setAddress("3018 winter");doctor.setCity("madison");doctor.setGender("M");doctor.setGroupId("UW1001");doctor.setHospital("1001");doctor.setName("jey");doctor.setState("WI");PatientInfo pat = new PatientInfo();pat.setAge(12);pat.setName("jey");pat.setSymbtom("Diabetes Insipidus");pat.setType("Diabetes");Rxdetail rxdetail = new Rxdetail();List<rxdetail> details = new ArrayList<rxdetail>();rxdetail.setDrugName("xx");rxdetail.setOther("red");rxdetail.setQty(11);rxdetail.setRxNum(11);details.add(rxdetail);CaseContext cont = new CaseContext();cont.setApprovalReq("N");cont.setApprovalReq("Supervisor");Prescription prescription = new Prescription();prescription.setDoctor(doctor);prescription.setPatientInfo(pat);prescription.setRxdetails(details);// collect all data in our map.Map<string object=""> params = new HashMap<string object="">();params.put("prescription", prescription);params.put("caseContext", cont);// start process.ProcessInstance processInstance = ksession.startProcess("healthcare.patientCaseProcess", params);// verify process started.System.out.println("process id " + processInstance.getProcessId());System.out.println("process id " + processInstance.getId()); }// Start our process by using RestAPI. // public static void main(String[] ar) {RestApi api = new RestApi();api.startProcess(); }翻譯自: https://www.javacodegeeks.com/2014/12/quick-guide-dissecting-jboss-bpm-cross-process-communication.html
總結
以上是生活随笔為你收集整理的快速指南:剖析JBoss BPM跨进程通信的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联通光猫如何连接无线路由器联通光猫如何桥
- 下一篇: 中国有火山爆发吗(建国以来只发生过一次本