إشعار
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تسجيل الدخول أو تغيير الدلائل.
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تغيير الدلائل.
ينطبق على: Azure Logic Apps (قياسي)
يوفر Azure Logic Apps Rules Engine سياق التنفيذ لمجموعة قواعد، والتي يمكنك إنشاؤها باستخدام Microsoft Rules Composer. يشرح هذا الدليل المفاهيم الأساسية حول كيفية عمل محرك القواعد ويوفر توصيات التحسين للعمليات والتنفيذ.
Core components
Ruleset executor
ينفذ هذا المكون الخوارزمية المسؤولة عن تقييم حالة القاعدة وتنفيذ الإجراء. منفذ مجموعة القواعد الافتراضي هو محرك استدلال تسلسلي قائم على شبكة التمييز ومصمم لتحسين العملية في الذاكرة.
Ruleset translator
This component takes a RuleSet object as input and produces an executable representation of the ruleset. ينشئ المترجم الافتراضي في الذاكرة شبكة تمييز مجمعة من تعريف مجموعة القواعد.
اعتراض تعقب مجموعة القواعد
يتلقى هذا المكون الإخراج من منفذ مجموعة القواعد ويحيل هذا الإخراج إلى أدوات تعقب ومراقبة مجموعة القواعد.
تقييم الشرط وتنفيذ الإجراء
محرك قواعد Azure Logic Apps هو محرك استدلال عالي الكفاءة يمكنه ربط القواعد بكائنات .NET أو مستندات XML. يستخدم محرك القواعد خوارزمية من ثلاث مراحل لتنفيذ مجموعة القواعد مع المراحل التالية:
Match
في مرحلة المطابقة، يطابق محرك القواعد الحقائق مقابل دالات التقييم التي تستخدم نوع الحقائق، وهي مراجع عناصر يتم الاحتفاظ بها في ذاكرة عمل محرك القواعد، باستخدام التقييمات المحددة في شروط القاعدة. للكفاءة، تحدث مطابقة النمط عبر جميع القواعد في مجموعة القواعد، ويتم مطابقة الشروط التي تتم مشاركتها عبر القواعد مرة واحدة فقط. قد يخزن محرك القواعد تطابقات الشرط الجزئي في ذاكرة العمل لتسريع عمليات مطابقة النمط اللاحقة. يحتوي الإخراج من مرحلة مطابقة النمط على تحديثات لجدول أعمال محرك القواعد.
Conflict resolution
في مرحلة حل التعارض، يفحص مشغل القواعد القواعد المرشحة للتنفيذ لتحديد المجموعة التالية من إجراءات القواعد التي سيتم تشغيلها، استنادا إلى مخطط حل محدد مسبقا. يضيف محرك القواعد جميع قواعد المرشح الموجودة أثناء مرحلة المطابقة إلى جدول أعمال محرك القواعد.
يستند نظام حل التعارض الافتراضي إلى أولويات القواعد داخل مجموعة القواعد. الأولوية هي خاصية قاعدة يمكنك تكوينها في Microsoft Rules Composer. كلما زاد الرقم، ارتفعت الأولوية. إذا تم تشغيل قواعد متعددة، يقوم مشغل القواعد بتشغيل الإجراءات ذات الأولوية الأعلى أولا.
Action
في مرحلة الإجراء، يقوم مشغل القواعد بتشغيل الإجراءات في القاعدة التي تم حلها. يمكن أن تؤكد إجراءات القاعدة حقائق جديدة في محرك القواعد، ما يؤدي إلى استمرار الدورة ويعرف أيضا باسم التسلسل الأمامي.
Important
لا تسبق الخوارزمية القاعدة قيد التشغيل حاليا. ينفذ مشغل القواعد جميع الإجراءات في القاعدة قيد التشغيل حاليا قبل تكرار مرحلة المطابقة. ومع ذلك، لن يتم تشغيل القواعد الأخرى على جدول أعمال محرك القواعد قبل أن تبدأ مرحلة المطابقة مرة أخرى. قد تتسبب مرحلة المطابقة في أن يقوم محرك القواعد بإزالة هذه القواعد من جدول الأعمال قبل تشغيلها.
Example
يوضح المثال التالي كيفية عمل خوارزمية المطابقة وحل التعارض والإجراءات المكونة من ثلاث مراحل:
القاعدة 1: تقييم الدخل
Declarative representation
الحصول على تصنيف ائتماني لمقدم الطلب فقط إذا كانت نسبة الدخل إلى القرض لمقدم الطلب أقل من 0.2.
IF — ثم التمثيل باستخدام كائنات الأعمال
IF Application.Income / Property.Price < 0.2 THEN Assert new CreditRating( Application)
القاعدة 2: تقييم التصنيف الائتماني
Declarative representation
الموافقة على مقدم الطلب فقط إذا كان التصنيف الائتماني لمقدم الطلب أكثر من 725.
IF — ثم التمثيل باستخدام كائنات العمل:
IF Application.SSN = CreditRating.SSN AND CreditRating.Value > 725 THEN SendApprovalLetter(Application)
يلخص الجدول التالي الحقائق:
| Fact | Description | Fields |
|---|---|---|
| Application | مستند XML يمثل طلب قرض منزل. | - الدخل: 65,000 دولار - SSN: XXX-XX-XXXX |
| Property | مستند XML يمثل الخاصية المراد شراؤها. | - السعر: 225,000 دولار |
| CreditRating | مستند XML يحتوي على التصنيف الائتماني لمقدم القرض. | - القيمة: 0-800 - SSN: XXX-XX-XXXX |
تحديثات لذاكرة العمل وجدول الأعمال
في البداية، تكون ذاكرة العمل وجدول الأعمال لمحرك القواعد فارغة. After your application adds the Application and Property facts, the rules engine's updates its working memory and agenda as shown:
| Working memory | Agenda |
|---|---|
| - Application - Property |
Rule 1 |
يضيف محرك القواعد القاعدة 1 إلى جدول أعماله لأن الشرط، Application.Income / Property.Price < 0.2، يقيم إلى true أثناء مرحلة المطابقة.
No CreditRating fact exists in working memory, so the condition for Rule 2 isn't evaluated.
القاعدة 1 هي القاعدة الوحيدة في جدول الأعمال، لذلك يتم تنفيذ القاعدة ثم تختفي من جدول الأعمال.
Rule 1 defines a single action that results in a new fact, which is the applicant's CreditRating document that is added to working memory.
بعد اكتمال تنفيذ القاعدة 1، يعود عنصر التحكم إلى مرحلة المطابقة.
The only new object to match is the CreditRating fact, so the results of the match phase are the following:
Working memory Agenda - Application
- Property
- CreditRatingRule 2 يتم الآن تنفيذ القاعدة 2، والتي تستدعي وظيفة ترسل خطاب موافقة إلى مقدم الطلب.
بعد اكتمال القاعدة 2، يعود عنصر التحكم إلى مرحلة المطابقة. ومع ذلك، لا تتوفر المزيد من الحقائق الجديدة لمطابقتها، وجدول الأعمال فارغ، لذلك يتم إنهاء التسلسل الأمامي، واكتمال تنفيذ مجموعة القواعد.
جدول الأعمال والأولوية
To understand how the Azure Logic Apps Rules Engine evaluates rules and executes actions, you must also learn about the concepts of agenda and priority.
Agenda
جدول أعمال محرك القواعد هو جدول زمني يقوم بقوائم انتظار القواعد للتنفيذ. جدول الأعمال موجود لمثيل محرك ويعمل على مجموعة قواعد واحدة، وليس سلسلة من مجموعات القواعد. عندما يتم تأكيد حقيقة في ذاكرة العمل، ويتم استيفاء شروط القاعدة، يضع المحرك القاعدة على جدول الأعمال وينفذ تلك القاعدة بناء على الأولوية. ينفذ المحرك إجراءات القاعدة من الأولوية العليا إلى الدنيا، ثم ينفذ الإجراءات للقاعدة التالية على جدول الأعمال.
يعامل محرك القواعد الإجراءات في قاعدة ككتلة، لذلك يتم تشغيل جميع الإجراءات قبل انتقال المحرك إلى القاعدة التالية. يتم تنفيذ جميع الإجراءات في كتلة قاعدة بغض النظر عن الإجراءات الأخرى في الكتلة. لمزيد من المعلومات حول التأكيد، راجع تحسين محرك القواعد باستخدام وظائف التحكم.
يوضح المثال التالي كيفية عمل جدول الأعمال:
Rule 1
IF
Fact1 == 1
THEN
Action1
Action2
Rule 2
IF
Fact1 > 0
THEN
Action3
Action4
When the Fact1 fact, which has a value of 1, is asserted into the engine, both Rule 1 and Rule 2 have their conditions met. لذلك، ينقل المحرك كلتا القاعئتين إلى جدول الأعمال لتنفيذ إجراءاتهما.
| Working memory | Agenda |
|---|---|
| الحقيقة 1 (القيمة =1) |
Rule 1: - Action1 - Action2 Rule 2: - Action3 - Action4 |
Priority
بشكل افتراضي، يتم تعيين جميع القواعد إلى 0 كأولوية للتنفيذ. ومع ذلك، يمكنك تغيير هذه الأولوية على كل قاعدة فردية. يمكن أن تتراوح الأولوية إلى أي جانب من 0 مع وجود أرقام أكبر ذات أولوية أعلى. ينفذ المحرك الإجراءات من الأولوية القصوى إلى الأولوية الأدنى.
يوضح المثال التالي كيفية تأثير الأولوية على تنفيذ الطلب للقواعد:
القاعدة 1 (الأولوية = 0)
IF
Fact1 == 1
THEN
Discount = 10%
القاعدة 2 (الأولوية = 10)
IF
Fact1 > 0
THEN
Discount = 15%
على الرغم من استيفاء شروط كلتا القاعده، يتم تنفيذ القاعدة 2 أولا بسبب أولويتها الأعلى. الخصم النهائي هو 10 بالمائة بسبب النتيجة من الإجراء المنفذ للقاعدة 1 كما هو موضح في الجدول التالي:
| Working memory | Agenda |
|---|---|
| Fact1 (value=1) |
Rule 2: Discount: 15% Rule 1: Discount: 10% |
الآثار الجانبية للإجراء
إذا كان تنفيذ الإجراء يؤثر على حالة كائن أو مصطلح مستخدم في الشروط، يقال إن هذا الإجراء له "تأثير جانبي" على هذا الكائن أو المصطلح. لا تعني هذه العبارة أن الإجراء له آثار جانبية، ولكن بدلا من ذلك، قد يتأثر الكائن أو المصطلح بإجراء واحد أو أكثر.
على سبيل المثال، افترض أن لديك القواعد التالية:
Rule 1
IF OrderForm.ItemCount > 100
THEN OrderForm.Status = "Important"
Rule 2
IF OrderList.IsFromMember = true
THEN OrderForm.UpdateStatus("Important")
In this example, OrderForm.UpdateStatus has a "side effect" on OrderForm.Status, meaning that OrderForm.Status is potentially affected by one or more actions.
The SideEffects property for .NET class members is set to true as the default value, which prevents the rules engine from caching a member with side effects. In this example, the rules engine doesn't cache OrderForm.Status in working memory. Instead, the engine gets the most recent value of OrderForm.Status every time the engine evaluates Rule 1. If the SideEffects property value is false, the rules engine caches the value when the engine evaluates OrderForm.Status for the first time. ومع ذلك، بالنسبة للتقييمات اللاحقة في سيناريوهات التسلسل الأمامي، يستخدم المحرك القيمة المخزنة مؤقتا.
The Microsoft Rules Composer currently doesn't provide a way for you to modify the SideEffects property value. However, you can programmatically set the SideEffects property value through the Business Rules Framework, which is a Microsoft .NET-compliant class library. You set this value at binding by using the ClassMemberBinding class to specify object methods, properties, and fields used in rule conditions and actions. The ClassMemberBinding class has a property named SideEffects, which contains a Boolean value that indicates whether accessing the member changes its value.
Performance considerations
يناقش هذا القسم كيفية أداء Azure Logic Apps Rules Engine في سيناريوهات مختلفة ومع قيم مختلفة لمعلمات التكوين والضبط.
Fact types
يستغرق محرك القواعد وقتا أقل للوصول إلى حقائق .NET من الوصول إلى حقائق XML. إذا كان لديك خيار بين استخدام حقائق .NET أو حقائق XML في مجموعة قواعد، ففكر في استخدام حقائق .NET للحصول على أداء أفضل.
Rule priority
The priority setting for a rule can range to either side of 0 with larger numbers having higher priority. يتم تنفيذ الإجراءات بالترتيب بدءا من الأولوية العليا إلى الأولوية الأدنى. When the ruleset implements forward-chaining behavior by using Assert or Update calls, you can optimize chaining by using the Priority property.
For example, suppose that Rule 2 has a dependency on a value that is set by Rule 1. If Rule 1 has higher priority, Rule 2 only executes after Rule 1 fires and updates the value. Conversely, if Rule 2 has a higher priority, the rule can fire once, and then fire again after Rule 1 fires and updates the fact in the condition for Rule 2. قد ينتج عن هذا السيناريو أو لا ينتج عنه النتائج الصحيحة، ولكن من الواضح أن الإطلاق مرتين له تأثير على الأداء مقابل الإطلاق مرة واحدة فقط.
لمزيد من المعلومات، راجع إنشاء قواعد باستخدام Microsoft Rules Composer.
عوامل التشغيل المنطقية OR
تم تحسين محرك القواعد لتنفيذ عوامل التشغيل المنطقية AND وإعادة بناء القاعدة التي وزعها المحرك في نموذج عادي مفكك بحيث يتم استخدام عامل التشغيل المنطقي OR فقط في المستوى الأعلى.
If you use more logical OR operators in conditions, the increase creates more permutations that expand the rules engine's analysis network. ونتيجة لذلك، قد يستغرق محرك القواعد وقتا طويلا لتطبيع القاعدة.
توفر القائمة التالية الحلول البديلة المحتملة لهذه المشكلة:
Change the rule into a disjunctive normal form so that the OR operator is only at the top level.
ضع في اعتبارك إنشاء القاعدة برمجيا لأنك قد تجد أن إنشاء قاعدة في نموذج عادي مفكك في Microsoft Rules Composer قد يكون صعبا.
Develop a helper component that performs the OR operations and returns a Boolean value, and then use the component in the rule.
قم بتقسيم القاعدة إلى قواعد متعددة وافحص القواعد علامة تم تعيينها بواسطة قاعدة تم تنفيذها مسبقا، أو استخدم كائن أكدته قاعدة تم تنفيذها مسبقا، على سبيل المثال:
Rule 1:
IF (a == 1 OR a == 3) THEN b = trueRule 2:
IF (b == true) THEN …Rule 1:
IF (a == 1 OR a == 3) THEN Assert(new c())Rule 2:
IF (c.flag == true) THEN …
Update calls
The Update function updates a fact that exists in the rules engine's working memory, which causes reevaluation for all the rules that use the updated fact in conditions. This behavior means Update function calls can be expensive, especially if many rules require reevaluation due to updated facts. في بعض الحالات، يمكنك تجنب الاضطرار إلى إعادة تقييم القواعد.
على سبيل المثال، ضع في اعتبارك القواعد التالية:
Rule 1
IF PurchaseOrder.Amount > 5
THEN StatusObj.Flag = true; Update(StatusObj)
Rule 2
IF PurchaseOrder.Amount <= 5
THEN StatusObj.Flag = false; Update(StatusObj)
All the remaining rules in the ruleset use StatusObj.Flag in their conditions. When you call the Update function on the StatusObj object, all the rules are reevaluated. Whatever the value is in the Amount field, all the rules except Rule 1 and Rule 2 are evaluated twice: once before the Update call and once after the Update call.
Instead, you can set the Flag value to false before you invoke the ruleset, and then use only Rule 1 in the ruleset to set the flag. In this case, the Update function is called only if the Amount value is greater than 5. The Update function isn't called if the amount is less than or equal to 5. This way, all the rules except Rule 1 and Rule 2 are evaluated twice only if the Amount value is greater than 5.
سلوك خاصية SideEffects
In the XmlDocumentFieldBinding and ClassMemberBinding classes, the SideEffects property determines whether to cache the value of the bound field, member, or column.
In the XmlDocumentFieldBinding class, the SideEffects property's default value is false. However, in the ClassMemberBinding class, the SideEffects property's default value is true.
لذلك، إذا كان المحرك يصل إلى حقل في مستند XML للمرة الثانية أو لاحقا داخل مجموعة القواعد، يحصل المحرك على قيمة الحقل من ذاكرة التخزين المؤقت. ومع ذلك، إذا كان المحرك يصل إلى عضو في كائن .NET للمرة الثانية أو لاحقا داخل مجموعة القواعد، يحصل المحرك على القيمة من كائن .NET، وليس من ذاكرة التخزين المؤقت.
This behavior means that if you set the SideEffects property in a .NET ClassMemberBinding to false, you can improve performance because the engine gets the member's value from the cache starting with the second time and onwards. However, you can only programmatically set the property value because the Microsoft Rules Composer doesn't expose the SideEffects property.
المثيلات والانتقائية
The XmlDocumentBinding and ClassBinding classes each have the following properties, which the rules engine uses their values to optimize condition evaluation. تسمح قيم الخصائص هذه للمحرك باستخدام أقل المثيلات الممكنة أولا في تقييمات الحالة ثم استخدام المثيلات المتبقية.
Instances: The expected number of class instances in working memory.
If you know the number of object instances beforehand, you can set the Instances property to this number to improve performance.
Selectivity: The percentage of class instances that successfully pass the rule conditions.
If you know the percentage of object instances that pass the conditions beforehand, you can set Selectivity property to this percentage to improve performance.
يمكنك فقط تعيين قيم الخصائص هذه برمجيا لأن Microsoft Rules Composer لا يعرضها.
دعم توريث الفئة
التوريث هو القدرة على استخدام جميع الوظائف من فئة موجودة وتوسيع هذه الإمكانات دون إعادة كتابة الفئة الأصلية، وهي ميزة رئيسية في لغات البرمجة الموجهة للعناصر (OOP).
يدعم Azure Logic Apps Rules Engine الأنواع التالية من توريث الفئة:
Implementation inheritance: The capability to use a base class's properties and methods with no other coding.
Interface inheritance: The capability to use only property names and method names, but the child class must provide the implementation.
باستخدام محرك القواعد، يمكنك كتابة القواعد من حيث فئة أساسية مشتركة، ولكن الكائنات المؤكدة في محرك القواعد يمكن أن تأتي من فئات مشتقة.
The following example has a base class named Employee, while the derived classes are named RegularEmployee and ContractEmployee:
class Employee
{
public string Status()
{
// member definition
}
public string TimeInMonths()
{
// member definition
}
}
class ContractEmployee : Employee
{
// class definition
}
class RegularEmployee : Employee
{
// class definition
}
على سبيل المثال، افترض أن لديك القواعد التالية:
Rule 1
IF Employee.TimeInMonths < 12
THEN Employee.Status = "New"
At run time, if you assert two objects, a **ContractEmployee** instance and a **RegularEmployee** instance, the engine evaluates both objects against the Rule 1.
You can also assert derived class objects in actions by using an **Assert** function. This function causes the engine to reevaluate rules that contain the derived object and the base type in their conditions as shown in the following example, which demonstrates implementation inheritance:
**Rule 2**
```text
IF Employee.Status = "Contract"
THEN Employee.Bonus = false
Assert(new ContractEmployee())
After the assertion, the engine reevaluates all rules that contain the Employee type or the ContractEmployee type in their conditions. على الرغم من تأكيد الفئة المشتقة فقط، يتم تأكيد الفئة الأساسية أيضا إذا تمت كتابة القواعد باستخدام أساليب في الفئة الأساسية، بدلا من الفئة المشتقة.