bre deep dive

Download BRE Deep Dive

Post on 12-Aug-2015

237 views

Category:

Technology

2 download

Embed Size (px)

TRANSCRIPT

  1. 1. 1 Sponsored & Brought to you by BRE Deep Dive Johann Cooper http://www.twitter.com/JohannCooper https://nz.linkedin.com/in/johanncooper
  2. 2. 2 Author: Integration Monday BizTalk BRE Deep Dive Johann Cooper Johann Cooper Principal Integration Consultant @JohannCooper
  3. 3. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 About me Principal Integration Consultant at Datacom NZ Co-author of the book SOA Patterns with BizTalk Server 2013 and Microsoft Azure Second Edition published by Packt Author of the blog Adventures inside the Message Box Creator of the BRE Pipeline Framework CodePlex project Author of the White Paper The A-Y of running BizTalk Server in Microsoft Azure published by BizTalk 360 Proud dad
  4. 4. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Agenda / Goals 1. Basics of BRE 2. Advanced BRE 3. BRE Pipeline Framework Goal To illustrate/evangelize how the usage of the BRE and the BRE Pipeline Framework can help you design and develop applications which are flexible to change Disclaimer I havent used every feature that Im discussing today in production applications, and in some cases Im forced to dumb down the topic in the interest of time. Feel free to discuss or counter any of my statements post the presentation
  5. 5. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Source code All source code (BT 2013R2/Visual Studio 2013) and sample files can be downloaded from the below link https://drive.google.com/file/d/0B9cj1Xr-- 0vFai0xRHI2aXJnbU0/view?usp=sharing
  6. 6. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Why should you use the BRE? Decouple your business or processing logic from pipeline/orchestration implementation Its not just for business rules, you can use it for application logic as well Its fast! Easy to change at runtime without full deployments Is versioned and can be source controlled Rules should be easy to understand if vocabularies are created correctly Its part of the BizTalk Server license, maximize your investment Even a business analyst can do it 1 - Basics of BRE
  7. 7. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Facts Discrete piece of information whose characteristics are to be assessed and updated Supported types .NET XML Database 1 - Basics of BRE
  8. 8. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Vocabularies Allow you to abstract away implementation of fact characteristics with friendly terms Example vocabulary definition GetColour : The primary colour of the cow .NET cow.Color SQL select [Color] from dbo.Cow XML - /cow/color CowVocabulary (Name Display Name) GetColour The primary colour of the cow GetLength The length of the cow in meters SetCowValue Update the cows value to ${0} 1 - Basics of BRE
  9. 9. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Vocabularies DEMO 1 - Basics of BRE
  10. 10. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules Made up of conditions and actions String together fact/vocabulary definitions with relevant predicates Example rule Set value for large green cows Condition If the cows length in meters is greater than 500 And the cows primary colour is equal to Green Action Update the cows value to $1000000000 1 - Basics of BRE
  11. 11. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules You dont have to use vocabularies but why wouldnt you? The below is just as valid. Example rule Set value for large green cows Condition cow.Length is greater than 500 cow.color is equal to Green Action SetCowValue 1000000000 1 - Basics of BRE
  12. 12. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Policies A collection of rules All conditions will be evaluated first, filling out the agenda, before any rules fire Order of conditions being evaluated is non-deterministic Order of rule actions firing is non-deterministic unless priorities are specified Order of actions firing within a rule is based on order inside the rule 1 - Basics of BRE
  13. 13. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Policy stages 1. Match condition evaluation and adding rules to agenda 2. Conflict resolution prioritizing sequence of execution 3. Action Firing actions in the relevant order 1 - Basics of BRE
  14. 14. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Assertion Making a fact available to a policy A policy can only deal with facts it is aware of Rules that depend on facts that are not asserted will never fire It is possible to enable static support for static .NET method via registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoftBusinessRules3.0StaticS upport 0 is default value which implies no static support 1 implies static support, with the static method being called each time 2 implies static support with the result of the static method being cached (only for conditions, not actions) and reused after the first execution. 1 - Basics of BRE
  15. 15. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 RETE Algorithm Very fast, and efficient way of evaluating multiple rules and creating your agenda Sacrifices memory for speed Breaks apart left and right hand side of conditions into separate node networks and applies the minimal amount of joins to evaluate conditions Might be best left to PhDs 1 - Basics of BRE
  16. 16. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rule Priorities Priorities can be assigned to rules Default value 0 Priority has nothing to do with conditions, just actions Higher the value, higher the priority Higher priority rules fire before lower priority rules So lower priority rules can override higher priority rules! 1 - Basics of BRE
  17. 17. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Policy Caching CacheEntries, CacheTimeOut, and PollingInterval can be configured via Registry or BizTalk config file - https://msdn.microsoft.com/en-us/library/aa548008.aspx 1 - Basics of BRE
  18. 18. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Side Effects Once you access an XML or SQL based fact value in a policy, its value will be cached and reused in other conditions/actions .NET members will not be cached by default This is controlled by the sideeffects property, can only be set programmatically or via XML export files, no support in composer 1 - Basics of BRE
  19. 19. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Side Effects This is a deep topic - further reading Charles Young - http://geekswithblogs.net/cyoung/archive/2007/04/09/111169.aspx My blog - https://adventuresinsidethemessagebox.wordpress.com/2012/11/20/biztal k-business-rules-policies-not-caching-net-facts-by-default/ 1 - Basics of BRE
  20. 20. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules/Policies/Assertion/Priorities DEMO 1 - Basics of BRE
  21. 21. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules testing Can right click on policy version in composer and choose Test Policy Can assert XML files or database connections via wizard Testing policy will result in change in state in asserted facts Must use a fact creator to assert .NET objects There is also a BizUnit 4.0 FactBasedRuleEngineStep test step 2 Advanced BRE
  22. 22. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules testing DEMO 2 Advanced BRE
  23. 23. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules traceability Can get equivalent information at runtime as you would when choosing Test Policy Can only do this programmatically, not in orchestration Can build your own tracing class based on Microsoft.RuleEngine. IRuleSetTrackingInterceptor Alternatively can make use of out of the box Microsoft.RuleEngine.DebugTrackingInterceptor 2 Advanced BRE
  24. 24. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Rules traceability DEMO 2 Advanced BRE
  25. 25. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Versioning and Source Control Can export vocabulary/policy definitions to XML using BRE Deployment Wizard or BizTalk Administration Console Can bulk export from BizTalk Administration Console Can copy old versions of vocabularies or policies and paste to create a new version and edit Orchestration always chooses latest version, but can be explicit from .NET (or ESB Toolkit / BRE Pipeline Framework) Can associate policies with an application, but beware that deleting the application is equivalent to deleting the policy If deleting a policy from BizTalk Admin Console, if it is the last policy to be associated with a vocabulary then the vocabulary will be deleted as well 2 Advanced BRE
  26. 26. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Versioning and Source Control DEMO 2 Advanced BRE
  27. 27. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Engine Control Functions Can control rules chaining through definitions contained within the Functions vocabulary Beware of endless loops, these can consume all the machines memory This is a topic in itself. We are only scratching the surface Assert/Update Re-evaluate conditions in all rules that make use of the asserted/updated fact. Update will only re-evaluate if the type is used in conditions, not if only in actions (in which case the actions will be left on the agenda) Retract/RetractByType Remove fact from rule engine. RetractByType removes all facts with a matching type while retract only removes a single instance Halt Stop the rules execution (tip use priority to control when this happens) 2 Advanced BRE
  28. 28. Copyright Datacom Group Limited 2014 Saturday, 18 July 2015 Engine Control Functions