jboss默认进程名称_快速指南:剖析JBoss BPM跨进程通信

jboss默认进程名称

技巧和窍门 (文章来宾与北美红帽公司高级解决方案架构师杰伊·保拉杰合着)

几周的提示与技巧文章将深入探讨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 request
   RuntimeEngine 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 request
   RuntimeEngine 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默认进程名称

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值