

How to Interact with Business Processes Using Camel Routes
以下为 快照 页面,建议前往来源网站查看,会有更好的阅读体验。
原文链接: https://blog.kie.org/2021/04/how-to-interact-with-business-processes-using-camel-routes.html
How to Interact with Business Processes Using Camel Routes
The JBPM KIE server has a rich set of REST APIs that allows control over business processes and other business assets. Interaction with business processes is straightforward and easily accessible. Usually these APIs are used by the Business Central component and custom applications. In this post I want to give a simple example of how to interact with business processes, deployed in a KIE server, using Apache Camel. Utilizing business processes in a camel route, as you will see, is pretty easy!
There is an available component in Camel called simply the JBPM component. Both consumers and producers are supported. The consumer side has already been covered by Maciej in this excellent post. My example will focus on the producer side.
What interactions are available?
The JBPM component uses exchange headers to hold the operations/commands used to interact with the KIE server. The query parameters in the URL holds the security and deployment information. The following is an example of an JBPM URL.
jbpm:http://localhost:8080/kie-server/services/rest/server?userName=myuser&password=mypass&deploymentId=mydeployment
That URL above will interact with the KIE server running on localhost port 8080, the container deployed as mydeployment, and using the user myuser and password mypass. Of course all these values can be parameterized.
The following table shows some of the interactions available as of version Apache Camel 3.8. The header key for the operation header is JBPMConstants.OPERATION. All supported header keys are listed in the JBPMConstants class.
OperationSupport HeadersDescriptionstartProcessPROCESS_IDPARAMETERSStart a process in the deployed container (in URL) and the process definition ID and any parameters.signalEventPROCESS_INSTANCE_ID
EVENT_TYPE
EVENTSignal a process instance with the signal (EVENT_TYPE) and payload (EVENT). If process instance ID is missing then the signal scope will be defaultgetProcessInstancePROCESS_INSTANCE_IDRetrieve the process instance using the ID. The resulting exchange body will be populated by a
org.kie.server.api.model.instance.ProcessInstance
object.completeWorkItemPROCESS_INSTANCE_IDWORK_ITEM_ID
PARAMETERSComplete the work item using the parameters.
You can find the complete list in the org.apache.camel.component.jbpm.JBPMProducer.Operation
enum.
Simple Example
In this example we’ll be using the following versions:
Install and start the JBPM KIE server.
> docker pull jboss/jbpm-server-full
> docker run -p 8080:8080 -p 8001:8001 -d --name jbpm-server-full jboss/jbpm-server-full:latest
Log into Business Central (http://localhost:8080/business-central/) using wbadmin/wbadmin as the credentials. In the default MySpace, create a project call test-camel and a business process in it call test-camel-process. Add a process variable call data of type String. Add a script task to print out data. Save and deploy the project.
To quickly stand up a Camel environment, we’ll be using Spring Boot. The following command will help you create the spring boot project:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.camel.archetypes \
-DarchetypeArtifactId=camel-archetype-spring-boot \
-DarchetypeVersion=3.8.0
In the resulting project, add the following dependency into the pom.xml file.
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jbpm-starter</artifactId>
</dependency>
Add the following to the application.properties file.
server.port = 8280
jbpm.server.url = http://localhost:8080/kie-server/services/rest/server
jbpm.server.user = wbadmin
jbpm.server.pass = wbadmin
jbpm.deployment.id = test-camel_1.0.0-SNAPSHOT
jbpm.process.id = test-camel.test-camel-process
jbpm.process.data = data
Modify the MySpringBootRouter.java file to add some routes. The following code snippet will start a process.
@Override public void configure() { from("timer:startprocess?delay=1000&period=5000") .to("direct:startprocess"); from("direct:startprocess") .setHeader(JBPMConstants.OPERATION, constant("CamelJBPMOperationstartProcess")) .setHeader(JBPMConstants.PROCESS_ID, simple("{{jbpm.process.id}}")) .process((Exchange exchange) -> { String dataName = exchange.getContext().resolvePropertyPlaceholders("{{jbpm.process.data}}"); Map<String, Object> params = new HashMap<>(); params.put(dataName, "hello world"); exchange.getIn().setHeader(JBPMConstants.PARAMETERS, params); }) .to("jbpm:{{jbpm.server.url}}?userName={{jbpm.server.user}}&password={{jbpm.server.pass}}&deploymentId={{jbpm.deployment.id}}"); }
The above example will send "hello world" as the data to start the process in the KIE server. By default without specifying JBPMConstants.OPERATION
, the operation will be to start the process. The reason the operation is set to CamelJBPMOperationstartProcess is the operation is an aggregation of the value of JBPMConstants.OPERATION
and the enum value defined in org.apache.camel.component.jbpm.JBPMProducer.Operation
. Unfortunately we cannot use the operation enum directly because it’s not exposed publicly.
猜你喜欢
-
1
Starting business processes using Kafka eventsLet’s check how we can model a business process, using the BPMN standard, that can react t...
-
0
Authenticated routes using react-routerPublished December 5, 2017 #react
-
30
I recently had an opportunity to work on a fantastic research and development project at Netguru. The goal of project (codename: “Wordguru”) was to create a card game that anyone can play with their friends. You can see t...
-
36
?? PHP Camel Caser - Lets you use built-in PHP functions in camel case - DivineOmega/php-camel-caser
-
80
README.md Apache Camel
-
28
This post was originally published here . Check out my new
-
1
KafkaA look at the Camel Kafka Consumer In this post let’s look at the Kafka Camel Component.
-
3
Camel Camel Camel - A Way to Get Amazon Stuff Cheaper May 18, 2019 The vast breadth of things on the Internet never fails to amaze me. And when I discover something new, I find that writing about it helps me...
-
1
A Steaming Pile of Camel Dung Oct 30, 2005 • {"login"=>"fuzzyblog", "email"=>"eric@appdata.com", "display_name"=>"fuzzyblog", "first_name"=>"Scott", "last_name"=>"Johnson"}
-
0
Apache Camel 3.8 and Java Flight Recorder In the upcoming Apache Camel 3.8 release we have a new Camel component to integrate with Java Flight Recorder.Camel is now capable of c...
关于极客头条
聚合每日国内外有价值,有趣的链接。