Apache Camel is extremely powerful integration library, comes with hundreds of components to integrate with 3rd party systems. jBPM on the other hand provides great support for business processes and cases. In many situations data produced by jBPM is required to be pushed to external systems or business processes would need to be informed about changes in external systems that can influence business logic.
So why not combine these two and provide state of the art business solution that can focus on business goals and yet integrate with pretty much anything in the world.
as you can see as soon as there will be events produced on the jbpm:events:processes a new exchange will be processed that will simply go over filter and get only beforeProcessStarted events (each event type is set as header) and the body is actual event produced by jBPM.
NOTE: if you need more than one on the same consumer type you should suffix it with sort of classifier to make the endpoints unique jbpm:events:process:startedOnly
Similar endpoints can be used for user tasks and cases
IMPORTANT: This improved camel-jbpm component is not yet released, it will go out with Apache Camel 2.23.0 release that is expected to be out in couple of days from now. So prepare yourself and make sure to give it a go.
A sample project with just camel logging the events can be found here.
So why not combine these two and provide state of the art business solution that can focus on business goals and yet integrate with pretty much anything in the world.
Improved camel-jbpm component
camel-jbpm component has been added in 2.6 version of Camel. At that time it was based on jBPM 6.5 and provided only producer based on kie-remote-client that interacts with jBPM console (aka workbench) REST api. It's been a while since then and even more important jBPM Console REST api for execution does not exists any more and same applies for kie-remote-client. It has been replaced completely with way more powerful kie server client.
So it was high time to improve the camel-jbpm component to first of all upgrade to latest version (7.14) and replace use of kie-remote-client with kie-server-client for producer usage. And to provide consumer support as well that will enable simple integration with outside world for pushing out data from jBPM.
So when it comes to consumer of camel-jbpm component users can now take advantage of following integrations of jBPM empowered by Camel
- ProcessEventListeners
- TaskLifeCycleEventListeners
- CaseEventListeners
- EventEmitter
All of these can be easily configured as Camel routes, here is a simple example that will be triggered upon process events being generated by jBPM
<routes xmlns="http://camel.apache.org/schema/spring"> <route id="processes"> <from uri="jbpm:events:process"/> <filter> <simple>${in.header.EventType} == 'beforeProcessStarted'</simple> <to uri="log:kjar.processes?level=INFO&showBody=true&showHeaders=true"/> </filter> </route> </routes>
as you can see as soon as there will be events produced on the jbpm:events:processes a new exchange will be processed that will simply go over filter and get only beforeProcessStarted events (each event type is set as header) and the body is actual event produced by jBPM.
NOTE: if you need more than one on the same consumer type you should suffix it with sort of classifier to make the endpoints unique jbpm:events:process:startedOnly
Similar endpoints can be used for user tasks and cases
- jbpm:events:tasks
- jbpm:events:cases
Configure routes
Routes can be configured either on application level (kie server or business app) or kjar level.
camel-jbpm component comes with KIE server extension that will be automatically registered in KIE Server when the jar file is present - see Installation section for more details on it.
Global routes should be created in the root of the application class path (kie-server.war/WEB-INF/classes) in a file name global-camel-routes.xml
Such global routes will apply to all deployed kjars in KIE Server.
KJAR specific routes can also be used by placing camel-routes.xml file in the root of kjar class path (src/main/resources folder of the kjar source). When such file is found new (kjar scoped) CamelContext is created with all routes defined in that file. These routes will only apply to that specific KIE Container.
Installation
Installation is really simple, it requires to drop two jar files into kie-server.war/WEB-INF/lib
- camel-core
- camel-jbpm
and that's it, start the server and you will see that Camel KIE Server extensions boots and does its thing :)
In case you would like to use another component to interact with, you need to do the same, drop the component jar file and its runtime dependencies. For the sake of example we use camel-kafka that requires these jar files to be placed in kie-server.war/WEB-INF/lib
- camel-kafka-2.19.0.jar
- kafka-clients-0.10.2.0.jar
- lz4-1.3.0.jar
- snappy-java-1.1.2.6.jar
Example
A simple use case to illustrate is to take advantage of the camel-jbpm consumer to react to events produced by jBPM for both tasks and processes
- for tasks we just log them to console
- for processes we push them out to Kafka
here is the camel-routes.xml for this example
<routes xmlns="http://camel.apache.org/schema/spring"> <route id="processes"> <from uri="jbpm:events:process:test"/> <filter> <simple>${in.header.EventType} starts with 'before'</simple> <transform> <simple>${in.header.EventType} for process instance ${body.processInstance.id}</simple> </transform> <to uri="kafka:TestLog?brokers=localhost:9092"/> </filter> </route> <route id="tasks"> <from uri="jbpm:events:task:test"/> <filter> <simple>${in.header.EventType} starts with 'before'</simple> <to uri="log:kjar.tasks?level=INFO&showBody=true&showHeaders=true"/> </filter> </route> </routes>
and here is just a short screencast showing this in action
IMPORTANT: This improved camel-jbpm component is not yet released, it will go out with Apache Camel 2.23.0 release that is expected to be out in couple of days from now. So prepare yourself and make sure to give it a go.
A sample project with just camel logging the events can be found here.