Here’s a topic that, without any particular reason, I never or I rarely addressed in my blog: Business Rules Engine (BRE)
The goal of this post is not to explain BRE but since it’s the first time that I cover something related to this topic, let’s first make a small introduction and share some notes and personal opinions about it.
Business Rules Engine (BRE)
Business Rules Engine (BRE) is a run-time inference engine that can link highly readable, declarative, semantically rich rules to any business objects (.NET components), XML documents, or database tables. It can evaluate rules against facts and initiates actions based on the results of that evaluation. This an optional component that comes out-of-the-box with BizTalk Server that enables you to directly create, modify and isolate a set of rules of business decisions (business rules). To be more accurate, since BizTalk Server 2004 version, Microsoft has introduced in the product the Business Rules Framework, a stand-alone application that consists of a number of modules, support components, and tools. The primary modules include:
- Business Rule Composer, a graphical user interface that enables developers, business analysts and administrators for constructing vocabularies and policies;
- Rule Engine Deployment Wizard for export, import, deploy or undeploy vocabularies and/or policies created in the Business Rule Composer;
- And the Run-Time Business Rule Engine that executes policies on behalf of a host application.
However, and in my opinion, this is the second BizTalk Server most misunderstood component only outweighed by BAM (Business Activity Monitoring). And one of the reasons “why?” Is that, Business Rule Composer is a tool initially designed for Business Analysts, or those responsible for the business, to create and update Business Rules at any time without affecting the code implemented by the developer team. In this perspective, or initial intention, the BizTalk Developer is not responsible for creating Business Rules, because, in reality, he will often be unfamiliar with the business, but he will be able to use or reuse them (BR) in their orchestrations to support a variety of scenarios like determining the execution path of a business process.
But one of the problems is that Business Rule Composer is a tool unfriendly, or too complex, for Business Analysts, which forces:
- Developers to stay with the task of creating them
- And to the Administrators to maintain them
With an unfamiliar tool (Developer are familiar with Visual Studio and Administrators with BizTalk Administration Console) and sometimes with unfamiliar terms (vocabularies, rules, and policies) to accomplish that.
Despite this component has not suffered any radical changes since 2004, BRE is still a powerful feature in BizTalk Server and you can make great things with it. Ricardo Torre mentioned in his series about BizTalk Server Tips that:
- Business Rule Engine is a high-performance engine to evaluate business rules even when compared with WF Rules
- And that Business Rule Engine is a good way of to modularize the constantly changing business logic that is often developed inside Orchestrations, making changes a more smooth process since updating policy to the latest version doesn’t require any downtime at all.
In fact, the most common application of BRE is to isolate business rule, in a centralized manner, from the BizTalk applications making it eminently reusable in a simple and efficient manner. But what many people don’t realize is that we can do many more things with it, for example:
- BRE can be used to store configuration data (or Application configurations), using a vocabulary, which is essentially parameters, or friendly names for the facts, that can be used within the execution of a rules policy. However, the vocabularies can also be accessed from C# code and they can be a wonderful way to abstract facts from their implementation.
- The Rule Engine Config Get Functoid, available in the BizTalk Mapper Extensions UtilityPack, allows you to obtain a definition value from a Vocabulary in the Business Rules Engine to be used inside your maps.
Before we went to the purpose of this post let me mention a particular note: Normally we have policies that consume vocabularies to generate rules, however:
- We can have simple vocabularies that are not consumed by any policy
- Or we can have simple policies that don’t consume any vocabulary
This week I have the necessary to migrate a simple policy (without any vocabulary) from an old version of BizTalk (2006 R2) to BizTalk Server 2013 R2. So what is necessary to migrate this artifacts’? Do I need to recreate everything or are they compatible?
How to migrate Business Rules Policies from BizTalk Server 2006/2006 R2 to BizTalk Server 2013 R2
Well, as I mentioned earlier in this post, BRE doesn’t suffer any radical changes since 2004, therefore, this is a very simple task to be accomplished. For that, you just only need to use the Rules Engine Deployment Wizard tool to import from your older environment and export them into your new environment.
Exporting policy from BizTalk Server 2006/2006 R2:
- Click “Start”, “Programs”, “Microsoft BizTalk Server 2006”, and then click “Business Rules Engine Deployment Wizard”.
- On the “Welcome to the Rules Engine Deployment Wizard” page, click “Next”.
- On the “Deployment Task” page, select “Export Policy/Vocabulary to file from database” option, and then click “Next”.
- On the “Policy Store” page, from the drop-down lists, select an available SQL Server computer and database, and then click “Next”.
- On the “Export Policy/Vocabulary” page:
- Select “Policy” option.
- From the Policy/Vocabulary drop-down list, select the desired policy you want to export.
- Click “Browse” to select the definition file path and name.
- And then click “Next “
- On the “Ready” page, review the information, and then click “Next”.
- On the “Exporting Policy/Vocabulary” page, after the export is completed, click “Next”.
- On the “Completing the Rules Engine Deployment Wizard” page, review the completion status, and then click “Finish”.
Importing a policy to BizTalk Server 2013 R2:
- In the BizTalk Server machine, press the “Windows key” to switch to the Start screen, type “Business Rules Engine Deployment Wizard” or “rules”, and then click “Business Rules Engine Deployment Wizard” option from the Search menu.
- On the “Welcome to the Rules Engine Deployment Wizard” page, click “Next”.
- On the “Deployment Task” page, select “Import and publish Policy/Vocabulary to the database from file” option, and then click “Next”.
- On the “Policy Store” page, from the drop-down lists, select an available SQL Server computer and database, and then click “Next”.
- On the “Import Rules Engine Policy/Vocabulary file” page:
- Click “Browse” to select the definition file that we previous export from BizTalk Server 2006/2006 R2.
- And then click “Next “
- On the “Ready” page, review the information, and then click “Next”.
- On the “Importing Policy/Vocabulary” page, after the import is completed, click “Next”.
- On the “Completing the Rules Engine Deployment Wizard” page, review the completion status, and then click “Finish”.
Now if we access to the Business Rule Composer you will notice that your policy is published are ready to be deployed.
I have done the following steps but now am getting an error as A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)