Eric D. Schabell: JBoss BPM Suite Quick Guide: Customize Your Rules Maven Repository

Wednesday, April 1, 2015

JBoss BPM Suite Quick Guide: Customize Your Rules Maven Repository

There is a fantastic JBoss Business Rules Management System (BRMS)* demo project that ties together rules, events and most importantly shows you how to use the scanner from a web application to pickup rule changes as they are pushed into production.

The demo is called the JBoss Cool Store and it gives you a lovely online web shop to work with while showcasing some of the various rules and features of the product.

What has been a bit of an issue for many people to get their heads around has been the KieScanner, a component you put into your application that then scans a maven repository for knowledge artifact updates.

This means you have the externalized business knowledge that can be maintained by users outside the scope of development of the online web application, in our case the web shopping cart.

The issue

With our local setup it was a bit confusing to start up the product, which would then rely on your personal local maven settings (settings.xml), to see it deploy any knowledge artifacts into the repository it found there, usually the local repository ($M2_HOME/.m2/repository).

Dynamically scanning for rule updates
from web shopping cart, without
new deployment.
Then we would build our online shopping cart web application which uses repository settings in the projects configuration (pom.xml) to find any dependencies it needs at build time. If the web application project did not find the knowledge artifacts in the remote repositories listed in its configuration, it would search the local repository and find the knowledge artifacts just fine.

The issues came about runtime, when we want to update our shipping rules for example, build and deploy a new version, but do not see the web application picking up the new version. We do see the scanner we setup picking up the new version but this is the session, not the application that is applying the knowledge artifacts. The application remains on the same static built version of our rules.

How to change this you ask?

Easy enough, we just need to modify your personal maven settings so we can add in the repository where JBoss BRMS is deploying its knowledge artifacts.

Externalizing maven repository

I am not a fan of tweaking personal maven settings, so we have customized the JBoss BRMS settings to point to a custom configuration that points to a temporary maven repository, thereby externalizing it so that our scanner can then also keep an eye on it for new rule updates.

What has changed and where is it located?
  • a system property was added to standalone.xml pointing to custom settings for maven
  • a custom settings.xml was added to specific location with externalized repository for the scanner
First off we need to specify a new custom maven setting location for JBoss BRMS by adding a system property to file found at:

jboss-eap-6.1/standalone/configuration/standalone.xml

The system property can be added to existing or if there are not yet any added, just copy this:

<system-properties>
    <property name="kie.maven.settings.custom" value="${jboss.home.dir}/bin/.settings.xml"/>
</system-properties>

We are locking the maven settings location here:

jboss-eap-6.1/bin/.settings.xml

Now we can look at the actual settings that need to define our repository location which we want to tie down to /tmp/maven-repo so that we can be sure to have our scanner find it. Also note in the below maven settings that the repository has the updatePolicy set to always so that the scanner always has the latest version of our knowledge artifacts.

<localRepository>/tmp/maven-repo</localRepository>

<repositories>
 <repository>
  <id>jboss-bpm-suite-repo</id>
  <name>JBoss BPM Suite Maven Repository</name>
  <url>file:///tmp/maven-repo</url>
  <layout>default</layout>
  <releases>
   <enabled>true</enabled>
   <updatePolicy>always</updatePolicy>
  </releases>
  <snapshots>
   <enabled>true</enabled>
   <updatePolicy>always</updatePolicy>
  </snapshots>
 </repository>
</repositories>

<pluginRepositories>
 <pluginRepository>
  <id>jboss-bpm-suite-repo</id>
  <name>JBoss BPM Suite Maven Repository</name>
  <url>file:///tmp/maven-repo</url>
  <layout>default</layout>
  <releases>
   <enabled>true</enabled>
   <updatePolicy>always</updatePolicy>
  </releases>
  <snapshots>
   <enabled>true</enabled>
   <updatePolicy>always</updatePolicy>
  </snapshots>
 </pluginRepository>
</pluginRepositories>

Now when you install the project initially, it builds a web application to deploy once that scans for new builds from JBoss BRMS where it can then pick up new knowledge artifacts as they become available in the externalized repository.
Adjust shipping tier pricing, build & deploy
project, watch scanner pick up changes!

All this happens dynamically and without a new web application redeployment, the next user gets the new rules.

Try adjusting the decision table shipping prices and then deploy a new set of your rules, the very next user of the JBoss Cool Store shopping cart will see the new shipping prices on the very next run after the scanner picks them up (10 seconds after deployment, watch the server logs).

[* It should be noted that we are talking about JBoss BRMS in this article, but the solution offered is interchangeable with JBoss BPM Suite as this is a super set adding processes to the rules and events in JBoss BRMS.]