我有一個通過Guvnor控制檯創建的drools規則,如果條件滿足,規則將驗證並將事實插入工作內存。規則是:訪問Drools返回Java代碼中的事實對象
1. | rule "EligibilityCheck001"
2. | dialect "mvel"
3. | when
4. | Eligibility(XXX== "XXX" , YYY== "YYY" , ZZZ== "ZZZ" , BBB == "BBB")
5. | then
6. | EligibilityInquiry fact0 = new EligibilityInquiry();
7. | fact0.setServiceName("ABCD");
8. | fact0.setMemberStatus(true);
9. | insert(fact0);
10. | System.out.println("Hello from Drools");
11. | end
執行的規則如下
RuleAgent ruleAgent = RuleAgent.newRuleAgent("/Guvnor.properties");
RuleBase ruleBase = ruleAgent.getRuleBase();
FactType factType = ruleBase.getFactType("mortgages.Eligibility");
Object obj = factType.newInstance();
factType.set(obj, "XXX", "XXX");
factType.set(obj, "YYY", "YYY");
factType.set(obj, "ZZZ", "XXX");
factType.set(obj, "BBB", "BBB");
WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(obj);
workingMemory.fireAllRules();
System.out.println("After drools execution");
long count = workingMemory.getFactCount();
System.out.println("count " + count);
一切看起來偉大與輸出如下
Java代碼:
Hello from Drools
After drools execution
count 2
我似乎無法找到一種方法將EligibilityInquiry
事實對象返回到我的Java代碼中,並獲取上述規則(serviceName
和status
)中設置的屬性。我已經使用了StatefulSession
的方法。
屬性文件通過用戶名和密碼與基本認證的快照鏈接。總共有2個事實:EligibilityInquiry
和Eligibility
。
我是相當新的流口水和任何幫助與上述讚賞。
感謝這對新手很好解釋。 – rockstar
感謝您的解釋,但對於同樣的問題,如果我必須通過REST api從Drools Rule Execution Server中檢索fact0,我該怎麼做? – Dminds
@Dminds您是否通過REST API獲得了從Drools Rule Execution Server中檢索fact0的答案。 –