{"id":13487654,"url":"https://github.com/JaryZhen/rulegin","last_synced_at":"2025-03-27T22:31:59.751Z","repository":{"id":41063396,"uuid":"128592158","full_name":"JaryZhen/rulegin","owner":"JaryZhen","description":"基于JavaScript Engine的轻量级规则引擎系统，重构于开源IOT项目thingboard","archived":false,"fork":false,"pushed_at":"2022-10-04T23:50:20.000Z","size":732,"stargazers_count":110,"open_issues_count":8,"forks_count":48,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-30T22:40:30.776Z","etag":null,"topics":["grpc-java","javascript","kafka","netty","spark","sping","zk"],"latest_commit_sha":null,"homepage":"https://thingsboard.io/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JaryZhen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-08T03:12:50.000Z","updated_at":"2024-08-23T12:28:10.000Z","dependencies_parsed_at":"2023-01-19T05:46:09.436Z","dependency_job_id":null,"html_url":"https://github.com/JaryZhen/rulegin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaryZhen%2Frulegin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaryZhen%2Frulegin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaryZhen%2Frulegin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaryZhen%2Frulegin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JaryZhen","download_url":"https://codeload.github.com/JaryZhen/rulegin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245935921,"owners_count":20696735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc-java","javascript","kafka","netty","spark","sping","zk"],"created_at":"2024-07-31T18:01:01.693Z","updated_at":"2025-03-27T22:31:59.717Z","avatar_url":"https://github.com/JaryZhen.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"\n\n \n## 一、背景\n\t规则引擎是一种根据规则中包含的指定条件，判断其能否匹配运行时刻的实时条件来执行规则中所规定的动作，\n\t用户可通过规则引擎设定消息处理规则，\n\t对指定的消息采取相应的措施来对设备进行监控和处理，如发送警告信息；\n    也可以将设备消息转发， 或者过滤到其他部件。\n\n#### 1.1 基本概念\n\t\t1)规则\n\t\t规则包含一个条件过滤器和多个动作。一个条件过滤器可以包含多个过滤条件。条件过滤器是多个布尔表达式的组合，其组合结果仍然是一个布尔类型的。\n\t\t在程序运行时，动作将会在条件过滤器值为真的情况下执行。\n\t\t2）动作\n\t\t动作是一段可执性的代码。\n\t\t3）消息队列\n\t\t消息队列是规则应用的主体， 消息队列中包含的消息具有各种属性。 这些属性出现在规则过滤条件中， 用于判断某条消息是否满足条件。 \n#### 1.2 典型的应用场景包括： \n\t 1.实时告警异常的数据；\n\t 2.计算一天内的温度最大最小和均值等；\n\t 3.将满足某条件的的数据转存以便查询；\n\t 4.过滤异常数据等。\n\n## 二、架构\n#### 2.1 逻辑模块：\n![哈哈](data/pic/ljt.png)\n#### 2.2 实现架构：\n![哈哈](data/pic/jg.png)\n\n## 三、 规则描述\n#### 3.1 规则BNFC\n\tRule :=  if Conditions then Actions\n\n\tConditions := Conditions and Condition |\n                  Conditions or Condition | \n\t\t\t\t  Condition\n\n\tCondition :=  Key Operator Value\n\t\tKey := Key name string | \n               Function（Key name string）\n\n\t   Function（Key name string） : = Window Function \n\t   WindowFunction := (day|hour| minute|second) (key, (min|max|mean|var))\n\t\n\tOperator:= Basic Operator | Advanced Operator\n\t\n\tBasic  Operator:=   \u003e | \u003c | = | \u003e= | \u003c= |\u003c\u003e \n\tAdvanced Operator := ℗ |SelfDef\n\t\n\tValue: = Static value | Key |Function| Expression(key) | Model \n\t\n\tActions:= Alarm | Filter | SelfDef\n\n#### 3.2 规则约束\n\t1.℗只能跟Model名\n\t2.Expression（key） 中只能有1个Key， 其他参数都是常量\n\t3.SelfDef action是可执性的代码段（java， Scala， python）\n\n\n## 四、Rule Engine Demo说明\n  - [规则定义详细定义](data/doc/规则定义.docx)\n- Step 1： Rule 定义 \n    \n\t\t{\n\t\t  \"name\": \"in-press-alarm\",\n\t\t  \"weight\": 0,\n\t\t  \"dataSource\": {\n\t\t    \"type\": \"kafka\",\n\t\t\t\"configuration\": {\n\t\t\t\t\"topic\": \"Suct_Data\",\n\t\t\t\t\"format\": \"null\",\n\t\t        \"keys\": [\n\t\t         \"Suct_Pres_Status\"\n\t\t        ]\n\t\t    }\n\t\t  },\n\t\t  \"filters\": [\n\t\t    {\n\t\t      \"name\": \"吸气压力状态\",\n\t\t      \"type\": \"kafkaWindow\",\n\t\t\t  \"configuration\": {\n\t\t\t  \"size\":2000,\n\t\t\t  \"step\":1000\n\t\t\t  },\n\t\t      \"condition\": \"Sum(Suct_Pres_Status) \u003e 70\"\n\t\t    }\n\t\t  ],\n\t\t  \"actions\": [\n\t\t    {\n\t\t      \"type\": \"Print\",\n\t\t      \"template\": \"吸气温度高\"\n\t\t    }\n\t\t  ]\n\t\t}\n- Step 2： Rule注册\n\n\t\tcurl -X POST -H 'Content-Type: application/json' -d @Rule.json @localhost:8080/api/rule\n- Step 3： Rule 启动\n\n\t\t首先Kafka 发送数据到Topic Suct_Data\n\t\tcurl -X POST @localhost:8080/api/rule/ID/activate\n- Step 4.   结果查验\n\n\t\t通过控制台来查看运行结果","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJaryZhen%2Frulegin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJaryZhen%2Frulegin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJaryZhen%2Frulegin/lists"}