Business is dynamic. Policies, rules, constraints are never stable and they amend/evolve with time. Processes, applications and workflows supporting any business model need to implement these changes with minimal maintenance and adoption hazards.
BizTalk Business Rule Engine (BRE) is a magnificent tool that scales out capabilities of policy/rule based applications and workflows. BRE became part of BizTalk from 2004 onwards. In BRE, business people can define “Rules”. Rules can be clubbed under “Policies”. “Facts” or say business information are passed through these policies to obtain desired business results.
Facts have two categories – Short Term Facts and Long Term Facts. Consider a loaning process of any Bank. We can think a “loan application” as short term fact. Short team facts are business information which changes per occurrence. On the contrary, “interest rates” do not change very regularly. This business information is steady and we can consider it a long term fact.
In BRE based applications/workflows, short term facts are supplied very frequently (generally with each process execution) while long term facts are supplied first time and then only when it changes. After first process execution cycle, long term facts are stored in rule engine memory and are reused over multiple execution cycles.
Long term facts are implemented using “Fact Retriever”. Fact Retriever is an entity which provisions long term facts to business policies. Only one fact retriever can be defined per published business policy.
How to Develop Fact Retriever
Fact Retriever are developed as “Class Library” and it implements “Microsoft.RuleEngine.IFactRetriever” interface. It is required to code “UpdateFacts” method which loads long term facts and passes to business rule engine.
Following are steps to create fact retriever –
- Sample applicaton supplies a XML document as fact.
- Create a class library project say “SampleFactRetriverApplication”.
- Add a class “SampleFactRetriever”.
- Add following code –
public class SampleFactRetriever : IFactRetriever
public object UpdateFacts(RuleSetInfo rulesetInfo, Microsoft.RuleEngine.RuleEngine engine, object factsHandleIn)
if (factsHandleIn == null)
//create an instance of the XML object
XmlDocument document = new XmlDocument();
//load the document (fact)
//create and instantiate an instance of typed XML document
TypedXmlDocument doc = new TypedXmlDocument("BTSFactRetriver.TestFact1", document);
//pass document to rule engine
factsHandleOut = doc;
factsHandleOut = factsHandleIn;
In implementation, first XML file is loaded. Then it is converted to typed xml document. Typed xml document makes sure that schema of fact XML document is same as fact schema defined in policy. "BTSFactRetriver.TestFact1" is name space of schema. Finally typed XML document is passed to rule engine.
- Sign assembly and build.
- Register assembly to Global Assembly Cache (GAC).
- Fact Retriever is ready.
Fact Retriever can be configured in two ways –
- In Business Rule Composer
- Programmatically using RuleSetExecutionConfiguration object.
I am going to cover composer part here.
- Open business rule composer.
- Select policy version in Policy Explorer.
- In Properties window, select Fact Retriever property.
- Click the ellipsis button in the Fact Retriever property to browse in the GAC for fact retriever object “SampleFactRetriverApplication.SampleFactRetriever”. Save.
- Configuration is over and you are ready to go.