1. 程式人生 > 其它 >如何在 SAP BTP 上建立以及消費 Business Rule Service

如何在 SAP BTP 上建立以及消費 Business Rule Service

官網連結:https://developers.sap.com/tutorials/cp-cf-businessrules07-ruleservice-ruleset.html

Create a rule service interface for an application to invoke the decision logic by associating the rule to a ruleset of the rule service.

建立 rule service interface 的目的:應用程式通過將規則與規則服務的規則集相關聯來呼叫決策邏輯。

A rule service is an interface or an end point that enables an application to invoke a decision logic.

rule service 可以看成一個介面或者 endpoint,應用程式通過呼叫 rule service,可以觸發 decision logic.

Rule set 是一系列 rule 的集合,工作於某個特定的場景。

A rule set can be linked to a rule service so that the set of rules in the rule set gets executed when the rule service is deployed.

規則集可以連結到規則服務,以便在部署規則服務時執行規則集內包含的所有規則。

建立一個新的 rule service:

從下拉選單裡選擇 vocabulary:

語義是:通過 Employee 資訊作為輸入,決策出 EquipmentInfo 作為決策結果:

建立另一個 rule service,用於決策是否需要 approval:

啟用整個專案:

點選 Deploy 按鈕,部署 rule service:

如果部署失敗,檢查該 Rule Service 使用到的 entity 是否已經啟用,或者是否已經新增到 Ruleset vocabulary 裡:

很明顯,這個 Equipment 維護錯了,應該修改成 Employee:

SAP API Business Hub 上找到 SAP Business Rules Service:

使用 Rule Execution API for Cloud Foundry 呼叫 Business Service:

給 wm_businessrules 建立一個新的 service key:

抄下 clientid, clientsecret 和 url 欄位,作為 SAP API Business Hub 裡維護 environment 的輸入值:

消費該 business rule service 的輸入 payload:

    {
  "RuleServiceId": "f27730d10cce4525ae111e647054d8f7",
  "Vocabulary": [
    {
      "Employee": {
        "IsFullTimeEmployee": true,
        "countryofCompany": "USA",
        "jobTitle": "Engineer II",
         "company": "2000"
       }
    }
  ]
}

更多Jerry的原創文章,盡在:"汪子熙":