Tuesday, August 21, 2012

Why use jBPM and Drools


I just wanted to give some intro to the people that are considering using jBPM but still need some picture as where this would fit in their system.

1. What is BPM?


Taken from Wiki:
Business process management (BPM) is a holistic management approach focused on aligning all aspects of an organization with the wants and needs of clients. It promotes business effectiveness and efficiency while striving for innovation, flexibility, and integration with technology. BPM attempts to improve processes continuously. It can therefore be described as a "process optimization process." It is argued that BPM enables organizations to be more efficient, more effective and more capable of change than a functionally focused, traditional hierarchical management approach.

From my perspecitve, simply said, BPM should allow company to circumvent complex development cycles, give more control to customer over what is happening in the process itself and significanetly cut the cost of creating new solutions for the customer as most of components should be reusable. Documentation and help are readily available and development is constant as jBPM is open source.

2. Why use it?


To develop a custom solution is sometimes needed but when exapanding usage and bringing in new technologies where companies are trying to cut costs, we need to be focused on how to implement what we have with anything that might potentialy benefit us and customers at the same time. This means using the knowledge of majority of the people that are alreay experts in the matter but they are not directly working for your company. Maintating and testing such complex sultions takes a lot of time and effort. Also, constantly thinking about new ways to improve functionality and tying the resources into this is not always the best idea, unless your budget allowes you to do it. Contributing to the community (should your company allow it) would be a much better and cost effective way of doing it.

3. What was the need in our company?


We are always faced with the question of how to improve the functionality of the system to allow it to easily integrate with various tools, but on the other hand, to make it so it is stable and reliable as our solution needs to be used in insurance industry. Most of the problems that we are solving are common for the insurance industry but going from customer to customer there are frequent requests to implement a specific functionality that separates one customer from another in the market. Having some competition just makes this process more intense as legacy systems are not so easily replaced.

BPM came into story as we needed more flexibility in our back end systems to allow customers to create and shape processes using only Desinger where we would create custom sevices that can be assembled into different processes with minimal help from development team.

4. How to implement and take the most from this technology?


This is the scenario that we envisioned on how BPM and Drools would be used:


  • Development team creates processes and back-end logic with custom work items where most of the logic that we already have is reused and fortified so it can be called independently
  • Development team creates initial processes to show how BPM should be used 
  • BA team creates initial rules using BRL and DRL file packed into the PKG so we can version every release and use agents to reload resources dynamically 
  • Development team creates integration of the BPM engine into the system
  • Customer starts modifying processes and submit them to Guvnor. These resources are automatically applied (after QA testing and busniess approvals)
  • Customer starts modifying rules by changing and removing old ones and introducing new rules as needed. Rules are dynamically loaded into application (no need for restart or recompiling)
  • Process is iterative and has minimal involvement from IT team (only for implementing new functionality)


When integrating BPM, there are several things to consider:


  1. Is your system stateful or stateless? BPM generaly uses stateful session, so you need to know the bounds and lifecycle of this session even if it is executed briefly.
  2. Where to create your Knowledge Base. Crating knowledge base can take time, so you can consider either creating it in some application scoped object that is initiated once or creating singleton object for the Knowledge Base as you access BPM engine.
  3. How to invoke rules? There is an option to invoke rules through BPM directly, but we chose to do it in the work item code by creating another stateless session. This gives us much more control over which objects are passed into the session and we can reuse code if we want to use Drools without BPM.
  4. How to load resources? KnowledgeBuilderFactory vs KnowledgeAgentFactory. Static vs dynamic. We chose this to be configurable to allow us to load resources from packages and to connect to Guvnor and load resources from there. If you are loading resources from Guvnor, you need to consider that the Guvnor will not only become your source control but integral part of the application. On the other hand, resources can be loaded dynamically from files too, if you choose not to use Guvnor. This allows you to change the process and deploy the resources without touching the application. You should not forget to start the listeners though, if using agent to check for changes in packages.
  5. Transport and security of the user tasks. If you need user tasks, you can use several different types of handlers (WorkItemHandler). Please note that you will need to build/configure some security around those. Sine the source is open, you can change queries that are executed through already defines interface by defining custom mapping-file in persistence.xml. 
  6. Versioning. When you deploy one ID of the process, you will still need the old one as you might have some processes persisted and in need of continuing. You will then copy process and create new version with different ID. When starting new process you will need to use new ID and also have both BPMN resources loaded as the one that is deserializing and continuing will need old definition. The other option is to fail the process or manually convert to new process.
  7. Transaction management. We needed to implement 2 data sources (one XA) to make this work, so plan where your transaction will start, join and where it will commit/rollback.
There are probably many more, but these were important to me.


I hope that I gave you some ideas on why would you choose jBPM in your application and hopefully this will make your customers happy. As always, to find extensive information, please use JBoss help site(s)/forums and manual as there is plenty of information there. You can get a lot of help from IRC too.

Thanks!

No comments: