Pular para o conteúdo principal

Using jBPM embedded and CDI in a JavaFX application

A few years ago I wrote about using jBPM remote API from JavaFX. That was straightforward because the remote APIs are usually simply wrappers to REST APIs running on server side.
Since then a few things happened:


  • jBPM is in version 7.7, that article was for jBPM 6.3.0!
  • In version 7 the Business Central execution server was replaced by Kie Server (we even wrote a JavaFX client for Kie Server)
  • A new jBPM services API was introduced and it is mature and ready for production use.
  • CDI 2.0 was released and it allows the use of CDI in standalone Java applications ( and in a JavaFX application as we described).

We could use jbpm embedded at that time, but we would have to make use of underlying Kie APIs (RuntimeManager, KieSession, etc), which I was not willing to use at that time. With services API we can easily bring jbpm to every Java application, just just one of its flavors: CDI, EJB, Spring or pure Java.

But what is different from using embedded jbpm from Kie Server? Basically the engine will run inside the Java client application, which means that it will not rely on a central server to execute the business processes:



There might be the case where you don't want to maintain a central server and put the execution on the client. It is hard to defend such model in Cloud Computing days. create docker image and orchestrate it on Openshift. And I agree with it, 96.9% (made up statistic) of the cases will be better handled by this model. However, with an embedded client the jbpm engine execution will happen on the client, which means that we will remove the server for processes execution and we will optionally share a database between the clients:



In this model you may have a shared database or a shared maven repository. The jBPM API is very flexible, you can run it without a database and loading process definitions from the file system. The use cases for it may be:
  • Small business: they may not want to maintain a server or contract a cloud service, but they know the advantages of using jBPM to model their processes;
  • IoT: you may want to have local processes execution in IoT devices and avoid a single point of access;
  • Apartment complex: control garage, residents, apartment occupancy, visitants flow and other aspects of an apartment complex  may be done using BPM tools.
In any case, I managed to run jBPM on a JavaFX application with CDI and I would like to share it with you. The source is already on my github and it uses the same view from the Rewards Client we used with the Business Central remote API. This is what you need to know:
  • We use CDI, which means that after configuring jBPM (see package ) we can simply inject jBPM service in our application (ProcessService, UserTaskService, RuntimeDataService and more);
  • You have two datasource: in memory H2 or MySQL, by default it will connect to MySQL, see the class DatasourceSetup for more information;
  • It is JavaFX and Java 8. in Java 11 JavaFX will be removed from the JDK and you may use OpenJFX and OpenJDK in your commercial application, get JavaFX support from Gluon (if you want) and jBPM embedded support from Red Hat (if you want). If you don't want it, you should (hopefully) be free to build your commercial application based on these APIs.
The application structure show us that we need a few classes to configure jBPM (see conf directory). The API usage happens on RewardsServiceEmbeddedCDI.



That is all I wanted to share. Usually BPM users are big company, but embedded jBPM is a flexible and lightweight alternative for those who don't want to use a central server for processes execution. Of course the same API can be used in a Web application, but we will talk about it in future posts.

Comentários

Postagens mais visitadas deste blog

Creating custom Work Item Handler in BPM Suite/jBPM 6

Hi all! In this post I am going to share my experience creating a work item handler for BPM Suite 6.0.3 (which is very similar to jbpm as explained in a previous post ). The Hello World Work Item Handler Let's create a really simple WorkItemHandler just to print "Hello World" in the console. Of course you can implement more feature and make it receive parameters, access database, web services, etc. But in this post we will keep it simple. Really simple. First thing to do is to create a maven project for my WorkItemHandler. Here's the pom.xml of my Maven project: Notice that we are importing jbpm dependency so we can find the java interface that is used to create work item handlers. Now we can start coding. Let's create a class name HelloWorkItemHandler in package org.jugvale.jbpm, here is the simple code: Now we can build our project and go to BPM Suite to configure it so we can use this workitem. Registering the WorkItemHandler UPDATE...

Using the REST Task from jBPM 6

In this post I am going to share my experience using the BPM Suite 6 REST Task. BPM Suite  X jBPM jBPM is a JBoss community project to offer an open source and efficient BPM Suite and BPM Suite is a product created by Red Hat based on jBPM. In this post I will be using BPM Suite because I have it installed already, but what I am going to described should work for jBPM as well.   REST Task  The REST Task is used to invoke a REST resource (or perform an HTTP Request) from your Business Process. You can set the URL, HTTP Method, timeout and credentials from the Process Modeller interface and when the process gets into that task, it will generate a HTTP Request and return the response as String. It is available on the left side pallet under the "Service Tasks" tab: The Target REST Web Service The service we are going to access from our process is a really simple one, that's why it is called simple-hello-rs and it is based on JBoss helloworld-rs qu...

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.