We have covered all the important aspects of using Drools as a rule engine. We've explored stateless and stateful Kie Sessions and interaction with business processes, and seen how complex event processing is managed. The last step we need to take is to understand the different ways Drools can interact with the rest of our application.
Drools is a framework; as such, it can interact with other frameworks in as many ways as we can imagine. In the next sections, we will discuss some of the most common design and architecture approaches to integrating Drools with the rest of our design, including some pros and cons for each approach. We will cover an in-detail explanation of:
The first thing we will need to address when designing how Drools should interact with the rest of our application components is how they will fit in the overall architecture; we will have specific requirements regarding how data will be fed into the rule engine, either from our own application or from external sources. Also, we must decide how information should be published back to our application from the rule engine, or how it should be exposed to external applications. We've already seen many mechanisms throughout previous chapters to communicate between Drools and the rest of the application (to name a few):
Also, we need to decide whether or not our rules should be running in a discrete or continuous fashion, based on the necessities of our domain logic. We will discuss this case in the next subsection.
As we discussed in Chapter 6, Complex Event Processing, we might have situations where the absence of input data on a Drools runtime might trigger a rule. For such cases, asynchronous management of rule execution is required. Even if this is not the case, we might still design our application as a set of asynchronous components connected through a common messaging bus, such as JMS, and still need to manage our rules in a way that accommodates asynchronous management.
If we need to execute our business rules in a synchronous manner, we can take a series of actions to simplify integrating our rule execution to our application, including:
fireAllRules
after the insertion of new data, we can get the rule execution information that might modify a global variable, and expose it in the response.If we need to execute our business rules in an asynchronous manner, we need to take care of a few other things:
fireUntilHalt
).These considerations will be affecting the full structure of our application, and not just the Drools runtime. The purpose of this discussion of common practices used in Drools asynchronous and synchronous uses is just to understand that we can adapt to any situation we design our applications to handle.
Once we take care of these considerations, we might start considering how the Drools runtime will be deployed along with the rest of our application.
3.131.38.14