KIE Server is a lightweight execution server that comes with various capabilities where out of the box are following:
It's time to introduce Wildfly Swarm (to those that haven't heard about it yet) ...
Actually it means a lot:
First thing, let's just start empty server that will let us manage it manually - creating containers, running rules and processes via REST api
Make sure you're in the project folder (where you executed maven build) and then simply run this command:
- BRM - rules execution (Drools)
- BPM - business process execution, task management, background jobs (jBPM)
- BPM-UI - visualize your bpm components on runtime such as process definition and instance (since 6.4)
- BRP - business resource planning (Optaplanner) (since 6.4)
It's by default packaged as JEE application (web archive) and deployed to various containers, such as:
- JBoss EAP
- Wildfly
- Tomcat
- WebLogic
- WebSphere
While all this is already quite nice coverage, we don't stay idle and do work on bringing more to you. Let's see what's coming next...
All the hype about micro service is bringing in tons of new stuff that allows alternative approach for packaging and deployment of our systems or services if you like. Taking into consideration what capabilities KIE Server comes with it would be a crime to not take advantage of it to start building micro services with it. Instead of rewriting all the stuff in different way.
It's time to introduce Wildfly Swarm (to those that haven't heard about it yet) ...
Swarm offers an innovative approach to packaging and running JavaEE applications by packaging them with just enough of the platform to "java -jar" your applicationSo what Wildfly Swarm means in context of KIE Server?
Actually it means a lot:
- first of all it allows us to build executable jars that will bring in KIE Server capabilities to simple java -jar way of working with all it's power!
- next you can have a "executable kjar" just by starting it with argument that identifies kjar to be available for execution (Group Artifact Version)
- you can still run in managed mode - connected to controller and managed from within controller but without a need to provision your application server
With this in mind let's take a look at how to use it with Wildfly Swarm.
- Clone this repository kie-server-swarm into your local environment.
- Build the project with maven (mvn clean package)
- Make sure you run it with latest Maven otherwise you might run into build errors - I tested it with 3.3.9 so it works certainly with it
- Once it's successfully build you'll find following file inside the target folder
- kie-server-swarm-1.0-swarm.jar
- Now you're ready to rock with KIE Server on Wildfly Swarm
but before we start our KIE Server on Swarm, let's look at what options we have for the project we just built. This project, same as KIE Server, is modularized and allows us to pick only the things we are interested with. While KIE Server allows to disable extensions on runtime (via system properties) sometimes it does not make sense to bring in lots of dependencies if they are not going to be used.
So you can build the project with following profiles:
- BRM - includes BRM capability of the KIE Server that allows rules execution only
- no server components besides REST is configured
- build it with - mvn clean package -PBRM
- BPM - includes both BRM and BPM capabilities of the KIE Server - this is the default profile
- configures Swarm to have transactions and data sources enabled
- build it with - mvn clean package -PBPM or mvn clean package
So why it's important to have it done as profiles? It's because the size of resulting file (executable jar) will be smaller. Moreover it reduces number of things Swarm is going to configure and boot when we start our system. So keep this in mind as it might become handy one day or another :)
Let's get our hands dirty with running KIE Server on Wildfly Swarm
First thing, let's just start empty server that will let us manage it manually - creating containers, running rules and processes via REST api
Make sure you're in the project folder (where you executed maven build) and then simply run this command:
java -Dorg.kie.server.id=swarm-kie-server -Dorg.kie.server.location=http://localhost:8380/server -Dswarm.port.offset=300 -jar target/kie-server-swarm-1.0-swarm.jar
Wait for a while to boot Wildfly Swarm and KIE Server on it. Once it's completed you should be able to access it at http://localhost:8380/server
NOTE: since KIE Server requires authentication, whenever you attempt to access its REST endpoints you need to logon - by default you should be able to logon with kieserver/kieserver1!
you can customize users and roles by editing following files:
Now let's examine a bit what all these parameters mean:
Last but not least, let's run it in fully managed way - with controller.
Before you start wildfly Swarm with KIE Server, make sure you start controller (KIE workbench) so you'll see how nicely it registers automatically upon start.
Once controller (workbench) is running issue following command:
NOTE: since KIE Server requires authentication, whenever you attempt to access its REST endpoints you need to logon - by default you should be able to logon with kieserver/kieserver1!
you can customize users and roles by editing following files:
kie-server-swarm/src/main/config/security/application-users.properties
kie-server-swarm/src/main/config/security/application-roles.properties
Now let's examine a bit what all these parameters mean:
- -Dorg.kie.server.id=swarm-kie-server - specifies the unique identifier of the kie server - it is important when running in managed mode but good to use it always to make it a habit
- -Dorg.kie.server.location=http://localhost:8380/server - specifies the actual location where our KIE Server is going to be available - this must be a direct URL to actual instance even it if's behind load balancer - again important when running in managed mode
- -Dswarm.port.offset=300 - sets global port offset to avoid port conflicts when running many instances of wildfly on same machine
Next, let's run our first executable KJAR... to do so we just extend the command from first run and add arguments to the execution
java -Dorg.kie.server.id=swarm-kie-server -Dorg.kie.server.location=http://localhost:8380/server -jar target/kie-server-swarm-1.0-swarm.jar org.jbpm:HR:1.0
as you can see the only difference is:
org.jbpm:HR:1.0
org.jbpm:HR:1.0
which is GAV of a KJAR that is going to be deployed upon start of KIE Server on Swarm. So with just single command line we have fully functional server with BPM capabilities and HR project deployed to it.
Last but not least, let's run it in fully managed way - with controller.
Before you start wildfly Swarm with KIE Server, make sure you start controller (KIE workbench) so you'll see how nicely it registers automatically upon start.
Once controller (workbench) is running issue following command:
java -Dorg.kie.server.id=swarm-kie-server -Dorg.kie.server.location=http://localhost:8380/server -Dorg.kie.server.controller=http://localhost:8080/kie-wb/rest/controller -jar target/kie-server-swarm-1.0-swarm.jar
Again, a singe parameter difference between the first command we used to start empty KIE Server on Swarm - in this case it's controller url:
- -Dorg.kie.server.controller=http://localhost:8080/kie-wb/rest/controller
Make sure that this URL matches your controller being deployed - it can differer in terms of
- host (localhost in this case)
- port (8080 in this case)
- context root (kie-wb in this case)
Now you're ready to rock with Wildfly Swarm and KIE Server to build your own micro services backed by business knowledge.
Enjoy your dive into Swarm and as usual comments are more than welcome.
Enjoy your dive into Swarm and as usual comments are more than welcome.