Drools开源业务规则引擎(六)- Drools Flow中RuleFlow文件即*.rf文件介绍

news/2024/10/9 15:24:58/

文章目录

  • Drools开源业务规则引擎(六)- RuleFlow文件即*.rf文件介绍
    • 1.\<header>
      • 1.1.\<imports>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 1.2.\<globals>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 1.3.\<functionImports>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 1.4.\<variables>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 1.5.\<exceptionHandlers>
        • a.标签格式
        • b.属性说明
        • c.示例代码
    • 2.\<nodes>
      • 2.1.\<start>/\<end>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.2.\<metaData>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.3.\<triggers>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.4.\<constraint>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.5.\<eventFilter>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.6.\<actionNode>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.7.\<ruleSet>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.8.\<split>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.9.\<join>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.10.\<timerNode>
        • a.标签格式
        • b.属性说明
        • c.示例代码
      • 2.11.\<eventNodeNode>
        • a.标签格式
        • b.属性说明
        • c.示例代码
    • 3.\<connections>
      • 标签格式
      • 属性说明
      • 示例代码
    • 4.案例代码
      • 4.1.依赖导入
      • 4.2.规则文件(DRL)
      • 4.3.规则流文件(DRF)
      • 4.4.测试方法

Drools开源业务规则引擎(六)- RuleFlow文件即*.rf文件介绍

Drools Flow简介:

​ Drools 4.0有一个简单的“RuleFlow”功能,用于编排规则。Drools 5.0引入了一个强大的(可扩展的)工作流引擎。它允许用户使用规则和流程来指定他们的业务逻辑(在流程和规则之间可以进行强大的交互),并提供一个统一的环境。

​ 从Drools5.2版本起,Drools Flow项目和jBPM项目已合并到jBPM项目中,称为jBPM5(官方文档地址:https://docs.jboss.org/jbpm/v5.0/userguide)。jBPM 5.0已经发布,Drools项目将使用jBPM5作为引擎来支持流程功能。Drools Flow作为一个子项目将不再存在,但其愿景将继续作为jBPM项目的一部分,仍然允许(可选但)业务规则、业务流程和复杂事件处理之间的高级集成以及所有三种范式的统一环境。

​ *.rf文件可以说是在Drools6.4版本之前的规则流文件,Drools6.4及之后的版本中 *.rf 是已经淘汰了,但功能和bpmn2是一样的。由于 *.rf文件在可读性上比bpmn2要强一些,所以本文会先从简单的rf文件入手,以便大家方便理解《Drools开源业务规则引擎(五)- jBPM流程图元素介绍》,同时,一些简单的流程也可以通过rf文件去实现,并且不需要可视化工具,也可以手搓代码。

1.<header>

<header> 元素用来定义流程文件的元数据信息。

子标签/元素

  • <imports>:导入外部的类和包。可以使用这些导入的类和包来定义规则和行为。

  • <globals>:定义全局变量,这些变量在整个流程中均可使用。

  • <variables>:定义自定义属性,并在流程中进行配置和使用。

  • <functionImports>:定义自定义的函数。

  • <exceptionHandlers>:用于定义处理流程中发生的异常情况的异常处理程序。

1.1.<imports>

a.标签格式
  <xs:element name="imports"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:import"/></xs:sequence></xs:complexType></xs:element><!-- 导入的import -->	<xs:element name="import"><xs:complexType><xs:attribute name="name" type="xs:string" use="required"/></xs:complexType></xs:element>
b.属性说明
  • name:导入外部的类和包名。
c.示例代码
<header><imports><import name="com.ahao.project.input.UserIn"/></imports>
</header>

1.2.<globals>

a.标签格式
<xs:element name="globals"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:global"/></xs:sequence></xs:complexType>
</xs:element>
<xs:element name="global"><xs:complexType><xs:attribute name="identifier" type="xs:string" use="required"/><xs:attribute name="type" type="xs:string" use="required"/></xs:complexType>
</xs:element>
b.属性说明
  • identifier:全局变量的标识符(名称)。
  • type:全局变量的类型。
c.示例代码
 <header><globals><global identifier="output" type="com.ahao.project.output.UserOut"/></globals></header>

1.3.<functionImports>

a.标签格式
<xs:element name="functionImports"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:functionImport"/></xs:sequence></xs:complexType></xs:element><xs:element name="functionImport"><xs:complexType><xs:attribute name="name" type="xs:string" use="required"/></xs:complexType></xs:element>
b.属性说明
  • name:带类型的函数名称。
c.示例代码
  <functionImports><functionImport name="com.ahao.project.util.StrUtil.stringPrint"/></functionImports>

1.4.<variables>

a.标签格式
  <!-- 对应类型:org.jbpm.process.core.context.variable.Variable --><xs:element name="variables"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:variable"/></xs:sequence></xs:complexType></xs:element><xs:element name="variable"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:type"/><xs:element ref="drools:value"/></xs:choice><xs:attribute name="name" type="xs:string" use="required"/></xs:complexType></xs:element><xs:element name="type"><xs:complexType><xs:attribute name="name" type="xs:string" use="required"/><xs:attribute name="className" type="xs:string" /></xs:complexType></xs:element><xs:element name="value"><xs:complexType><xs:simpleContent><xs:extension base="xs:string"/></xs:simpleContent></xs:complexType></xs:element>
b.属性说明
  • name:变量名称。
    • type:变量类型。
      • name:类型的全路径类名(org.jbpm.process.core.datatype.impl.type包下)。
      • className:类名。
    • value:变量值。
c.示例代码
		<variables><variable name="str"><type name="org.jbpm.process.core.datatype.impl.type.StringDataType" className="String"/><value>测试内容</value></variable></variables>

1.5.<exceptionHandlers>

a.标签格式
  <!-- 对应类型:org.jbpm.compiler.xml.processes.ExceptionHandlerHandler --><xs:element name="exceptionHandler"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:action"/></xs:sequence><xs:attribute name="faultName" type="xs:string" use="required"/><xs:attribute name="type" type="xs:string" use="required"/><xs:attribute name="faultVariable" type="xs:string"/></xs:complexType></xs:element><!-- org.jbpm.workflow.core.node.ActionNode --><xs:element name="action"><xs:complexType><xs:simpleContent><xs:extension base="xs:string"><xs:attribute name="name" type="xs:string"/><xs:attribute name="type" type="xs:string"/><xs:attribute name="dialect" type="xs:string"/></xs:extension></xs:simpleContent></xs:complexType></xs:element>
b.属性说明
  • faultName:要处理的异常的类型或名称。
  • type:ExceptionHandler类型。
    • 可选值:action。
  • faultVariable:可选的变量名称,用来存储异常对象的引用。
  • exceptionHandler:定义了处理Java.lang.Exception类型异常的处理逻辑。
c.示例代码
  <header><exceptionHandlers><exceptionHandler faultName="java.lang.NullPointerException" type="action"><action dialect="java" type="expression">System.out.println("+++++++异常了+++++++++");</action></exceptionHandler></exceptionHandlers></header>

可以在流程中加入以下action节点,所抛出的异常会被上面的异常处理器捕获

Integer i = null; System.out.println("-----流程节点123-------"); System.out.println(i.toString());

在这里插入图片描述

2.<nodes>

规则流(RuleFlow)文件中定义节点的元素。节点表示流程中的一个步骤或活动,可以是任务、决策点、子流程等等。

公共属性

  • id:指定节点的唯一标识符。
  • name:指定节点的名称。
  • xy:指定节点在画布上的位置。
  • widthheight:指定节点的宽度和高度。

以上是节点的公共属性,后续小节将不会再过多说明。

子标签

<xs:element ref="drools:start"/>
<xs:element ref="drools:end"/>
<xs:element ref="drools:actionNode"/>
<xs:element ref="drools:ruleSet"/>
<xs:element ref="drools:split"/>
<xs:element ref="drools:join"/>
<xs:element ref="drools:milestone"/>
<xs:element ref="drools:subProcess"/>
<xs:element ref="drools:workItem"/>
<xs:element ref="drools:timerNode"/>
<xs:element ref="drools:humanTask"/>
<xs:element ref="drools:composite"/>
<xs:element ref="drools:forEach"/>
<xs:element ref="drools:eventNode"/>
<xs:element ref="drools:fault"/>
<xs:element ref="drools:state"/>
<xs:element ref="drools:dynamic"/>

2.1.<start>/<end>

<start>表示规则流的起点节点,<end>表示规则流的结束节点。

a.标签格式
  <!-- 起始节点 --><xs:element name="start"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/><xs:element ref="drools:triggers"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/></xs:complexType></xs:element><!-- 结束节点 --><xs:element name="end"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/><xs:attribute name="terminate" type="xs:string"/></xs:complexType></xs:element>
b.属性说明
  • <nodes>公共属性。
c.示例代码
<nodes><start id="1" name="Start"  height="40"/><end id="4" name="End" x="372" y="77" width="80" height="40" />
</nodes>

2.2.<metaData>

规则引擎中用于为规则和规则流(RuleFlow)等元素定义和存储元数据。元数据是与规则和规则流相关的附加信息,可以帮助规则引擎对规则进行管理、优化和执行。

元数据可以包含各种类型的信息,例如规则的作者、版本号、创建日期、规则状态等等。这些信息可以用于文档生成、规则管理、规则版本控制、规则访问控制或其他目的。

a.标签格式
  <xs:element name="metaData"><xs:complexType><xs:choice minOccurs="0" maxOccurs="1"><xs:element ref="drools:value"/></xs:choice><xs:attribute name="name" type="xs:string" use="required"/></xs:complexType></xs:element>
b.属性说明
  • name:名称。
  • value:值。
c.示例代码
<nodes><start id="1" name="Start"  height="40" ><metaData name="author"><value>AHAO</value></metaData></start>
</nodes>

2.3.<triggers>

触发器,用来在特定条件下触发某个节点的条件或事件。

a.标签格式
  <!-- 对应类型:org.jbpm.compiler.xml.processes.TriggerHandler --><xs:element name="triggers"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:trigger"/></xs:choice></xs:complexType></xs:element><xs:element name="trigger"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:constraint"/><xs:element ref="drools:eventFilters"/><xs:element ref="drools:mapping"/></xs:choice><xs:attribute name="type" type="xs:string" use="required"/></xs:complexType></xs:element>
b.属性说明
  • type:触发器类型。
    • 可选值:constraint,event。
c.示例代码
<triggers><trigger type="constraint"><constraint dialect="mvel" type="rule" priority="1">UserIn(age > 10)</constraint></trigger>
</triggers>

2.4.<constraint>

用于在规则引擎中定义规则条件。它指定了规则的条件表达式,只有当条件满足时,规则引擎才会执行该规则所定义的动作。

a.标签格式
  <xs:element name="constraint"><xs:complexType><xs:simpleContent><xs:extension base="xs:string"><xs:attribute name="toNodeId" type="xs:string"/><xs:attribute name="toType" type="xs:string"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="priority" type="xs:string"/><xs:attribute name="type" type="xs:string"/><xs:attribute name="dialect" type="xs:string"/></xs:extension></xs:simpleContent></xs:complexType></xs:element>
b.属性说明
  • toNodeId:在条件满足时要执行的目标节点。
  • toType:目标类型。
  • name:名称。
  • priority:优先级。
  • type:指定条件类型。
    • 可选值:rule,code。
  • dialect:语义。
    • 可选值:mvel,java,JavaScript。
c.示例代码
<!-- rule mvel -->
<constraint type="rule" dialect="mvel" priority="1">UserIn(age > 10)
</constraint><!-- code java -->
return person.getAge() > 20;
<!-- code mvel -->
return person.age > 20;
<!-- code JavaScript -->
person.age > 20

2.5.<eventFilter>

过滤事件的类型,只有满足特定事件类型的事件才能在规则流中进行处理。对应org.jbpm.process.core.event.EventTypeFilter 类型。

a.标签格式
  <xs:element name="eventFilters"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:eventFilter"/></xs:sequence></xs:complexType></xs:element><xs:element name="eventFilter"><xs:complexType><xs:attribute name="type" type="xs:string" use="required"/><xs:attribute name="eventType" type="xs:string" use="required"/></xs:complexType></xs:element>
b.属性说明
  • type:事件过滤类型。
    • 可选值:eventType。
  • eventType:事件类型。
c.示例代码
<eventFilters><eventFilter type="eventType" eventType="MyEventType"/>
</eventFilters>

2.6.<actionNode>

执行某种特定行为或操作的行为节点。

a.标签格式
  <xs:element name="actionNode"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/><xs:element ref="drools:action"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/></xs:complexType></xs:element><xs:element name="action"><xs:complexType><xs:simpleContent><xs:extension base="xs:string"><xs:attribute name="name" type="xs:string"/><xs:attribute name="type" type="xs:string"/><xs:attribute name="dialect" type="xs:string"/></xs:extension></xs:simpleContent></xs:complexType></xs:element>
b.属性说明
  • name:名称。
  • type:行为类型。
    • 可选值:expression。
  • dialect:语义。
    • 可选值:java,mvel。
c.示例代码
<actionNode id="12">
<!--      <action type="expression" dialect="java" name="行为节点">-->
<!--        System.out.println("行为节点-全局变量[java]:"+output.getAgeStages());-->
<!--      </action>--><action type="expression" dialect="mvel" name="行为节点">System.out.println("行为节点-全局变量[mvel]:"+output.ageStages);</action>
</actionNode>

2.7.<ruleSet>

规则集,表示一组相关的规则的集合。

a.标签格式
<xs:element name="ruleSet"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/><xs:element ref="drools:timers"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/><xs:attribute name="ruleFlowGroup" type="xs:string"/></xs:complexType></xs:element>
b.属性说明
  • ruleFlowGroup:规则流分组,对应于drl文件中的ruleflow-group属性。
c.示例代码
<ruleSet id="2" name="规则流分组1" ruleFlowGroup="Group1">
</ruleSet>

2.8.<split>

分支节点,用于创建分支,将规则流的执行流程拆分成多个并行的分支(相当于网关)。

a.标签格式
<xs:element name="split"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/><xs:element ref="drools:constraints"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/><xs:attribute name="type" type="xs:string"/></xs:complexType>
</xs:element>
b.属性说明
  • type:以下是可选类型。(org.jbpm.workflow.core.node.Split)。
    • 0:TYPE_UNDEFINED。未定义类型
    • 1:TYPE_AND。所有的分支路径都必须满足条件,才能够通过分裂节点。
    • 2:TYPE_XOR。只有一个分支路径能够满足条件,才能够通过分裂节点。
    • 3:TYPE_OR。至少有一个分支路径能够满足条件,就可以通过分裂节点。
c.示例代码
<split id="123" type="2"><constraints><constraint toNodeId="2" type="rule" dialect="mvel">UserIn(age &lt;= 10)</constraint><constraint toNodeId="3" type="rule" dialect="mvel">UserIn(age > 10)</constraint></constraints>
</split>

2.9.<join>

合并节点,用于定义流程的合并行为。(相当于合并网关,配合<split>标签一起使用)

a.标签格式
  <xs:element name="join"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/><xs:attribute name="type" type="xs:string"/><xs:attribute name="n" type="xs:string"/></xs:complexType></xs:element>
b.属性说明
  • type:以下是可选类型。(org.jbpm.workflow.core.node.Join)。
    • 0:TYPE_UNDEFINED。未定义类型
    • 1:TYPE_AND。合并节点要求所有传入的分支都执行完毕后,才能够继续执行合并节点之后的操作。
    • 2:TYPE_XOR。只有一个分支路径能够满足条件,才能够执行合并节点之后的操作。
    • 3:TYPE_DISCRIMINATOR。只有一个分支路径能够满足条件,才能够执行合并节点之后的操作。
    • 4:TYPE_N_OF_M。至少有n个分支路径能够满足条件,才能够执行合并节点之后的操作。
    • 5:TYPE_OR。至少有一个分支路径能够满足条件,才能够执行合并节点之后的操作。
  • n:满足条件分支数量。(当类型为TYPE_N_OF_M生效)
c.示例代码
<join id="1234" type="5"></join>

2.10.<timerNode>

定时器节点,在指定的时间点或时间间隔执行后续操作。

a.标签格式
  <xs:element name="timerNode"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/><xs:attribute name="delay" type="xs:string"/><xs:attribute name="period" type="xs:string"/></xs:complexType></xs:element>
b.属性说明
  • delay:延迟时间
  • period:循环周期
c.示例代码
<timerNode id="5" delay="1s" period="1d"/>

2.11.<eventNodeNode>

事件节点需要指定节点感兴趣的事件类型。它还可以定义变量的名称,该变量将接收与该事件相关联的数据。这允许流程中的后续节点访问事件数据,并根据这些数据采取适当的操作。

a.标签格式
<xs:element name="eventNode"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:metaData"/><xs:element ref="drools:eventFilters"/></xs:choice><xs:attribute name="id" type="xs:string" use="required"/><xs:attribute name="name" type="xs:string"/><xs:attribute name="x" type="xs:string"/><xs:attribute name="y" type="xs:string"/><xs:attribute name="width" type="xs:string"/><xs:attribute name="height" type="xs:string"/><xs:attribute name="variableName" type="xs:string"/><xs:attribute name="scope" type="xs:string"/></xs:complexType></xs:element>
b.属性说明
  • variableName:变量名称

  • scope:发送事件信号的方式

    • Internal:内部

      • kcontext.getProcessInstance().signalEvent(type, eventData);
        
    • external:外部

      • ksession.signalEvent(type, eventData);
        
c.示例代码
 <eventNode id="61" variableName="str" scope="external"><eventFilters><eventFilter type="eventType" eventType="myEvent"/></eventFilters></eventNode>
<!--kieSession.signalEvent("myEvent","Singal Event");
-->

3.<connections>

用于定义规则流中不同节点之间的连接关系。在规则引擎中,规则流可以被看作是一系列规则节点的有向图,并且节点之间的连接定义了规则执行的先后顺序。 <connections> 元素应该包含一个或多个 <connection> 子元素,每个 <connection> 元素定义了两个节点之间的连接。

标签格式

<xs:element name="connections"><xs:complexType><xs:sequence minOccurs="0" maxOccurs="unbounded"><xs:element ref="drools:connection"/></xs:sequence></xs:complexType>
</xs:element>
<xs:element name="connection"><xs:complexType><xs:attribute name="from" type="xs:string" use="required"/><xs:attribute name="to" type="xs:string" use="required"/><xs:attribute name="fromType" type="xs:string"/><xs:attribute name="toType" type="xs:string"/><xs:attribute name="bendpoints" type="xs:string"/></xs:complexType>
</xs:element>

属性说明

  • from:连接的起始节点(id)。
  • to:连接的目标节点(id)。
  • fromType:表示起始节点的类型。
  • toType:表示目标节点的类型。
  • bendpoints:连接的弯曲点。

示例代码

  <nodes><start id="1" name="Start"  height="40" /><end id="2" name="End" height="40" /></nodes><connections><connection from="1" to="2" /></connections>

4.案例代码

4.1.依赖导入

        <dependency><groupId>org.jbpm</groupId><artifactId>jbpm-bpmn2</artifactId><version>7.6.0.Final</version></dependency>

4.2.规则文件(DRL)

package drools.ruleflow;
dialect  "mvel"// 导入输入类型
import com.ahao.project.input.UserIn;
global com.ahao.project.output.UserOut output;rule "group1"
ruleflow-group "Group1"
when$in:UserIn(age <= 10)
thenoutput.setAgeStages("<=10");
endrule "group2"
ruleflow-group "Group2"
when$in:UserIn()
thenoutput.setAgeStages(">>>>>10");
end

4.3.规则流文件(DRF)

<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"type="RuleFlow" name="RuleFlow_Demo" id="RFDemo" package-name="drools.ruleflow"><header><imports><import name="com.ahao.project.input.UserIn"/><import name="com.ahao.project.util.DateTimeUtil"/></imports><globals><global identifier="output" type="com.ahao.project.output.UserOut"/></globals><variables><variable name="str"><type name="org.jbpm.process.core.datatype.impl.type.StringDataType" className="String"/><value>测试内容</value></variable></variables><exceptionHandlers><exceptionHandler faultName="java.lang.NullPointerException" type="action"><action dialect="java" type="expression">System.out.println("+++++++异常了+++++++++");</action></exceptionHandler></exceptionHandlers></header><nodes><start id="1" name="Start" height="40"><metaData name="TriggerMapping"><value>AHAO</value></metaData><triggers><trigger type="event"><eventFilters><eventFilter type="eventType" eventType="None"/></eventFilters></trigger></triggers></start><actionNode id="12"><!--      <action type="expression" dialect="java" name="行为节点">--><!--        System.out.println("行为节点-全局变量[java]:"+output.getAgeStages());--><!--      </action>--><action type="expression" dialect="mvel" name="行为节点">System.out.println("行为节点-全局变量[mvel]:"+output.ageStages);</action></actionNode><split id="123" type="2"><constraints><constraint toNodeId="2" type="rule" dialect="mvel">UserIn(age &lt;= 10)</constraint><constraint toNodeId="3" type="rule" dialect="mvel">UserIn(age > 10)</constraint></constraints></split><join id="1234" type="3"></join><ruleSet id="2" name="Verify" x="162" y="77" width="80" height="40" ruleFlowGroup="Group1"></ruleSet><ruleSet id="3" name="Calculation" x="267" y="77" width="80" height="40" ruleFlowGroup="Group2"/><actionNode id="41"><!--      <action type="expression" dialect="java" name="行为节点">--><!--        System.out.println("行为节点-全局变量[java]:"+output.getAgeStages());--><!--      </action>--><action type="expression" dialect="mvel" name="结束行为节点">System.out.println(DateTimeUtil.now()+": 结束行为!!!!!");</action></actionNode><eventNode id="61" variableName="str" scope="external"><eventFilters><eventFilter type="eventType" eventType="None"/></eventFilters></eventNode><timerNode id="5" delay="1s"/><actionNode id="42"><!--      <action type="expression" dialect="java" name="行为节点">--><!--        System.out.println("行为节点-全局变量[java]:"+output.getAgeStages());--><!--      </action>--><action type="expression" dialect="mvel" name="结束前行为节点">System.out.println(DateTimeUtil.now()+": 结束前!!!!");</action></actionNode><end id="4" name="End" x="372" y="77" width="80" height="40"/></nodes><connections><connection from="1" to="12"/><connection from="12" to="123"/><connection from="123" to="2"/><connection from="123" to="3"/><connection from="2" to="1234"/><connection from="3" to="1234"/><connection from="1234" to="41"/><connection from="41" to="61"/><connection from="61" to="5"/><connection from="5" to="42"/><connection from="42" to="4"/></connections></process>

4.4.测试方法

    @Testpublic void test() throws InterruptedException {// 获取文件内容String drl = ResourceUtil.fileContent("classpath:drools/ruleflow/rule-flow.drl");String rf = ResourceUtil.fileContent("classpath:drools/ruleflow/RuleFlowDemo.rf");KieHelper kieHelper = new KieHelper();KieBaseConfiguration kieBaseConfiguration = kieHelper.ks.newKieBaseConfiguration();// 加入文件内容,以便编译文件kieHelper.addContent(drl, ResourceType.DRL);kieHelper.addContent(rf,ResourceType.DRF);KieBase kieBase = kieHelper.build(kieBaseConfiguration);KieSession kieSession = kieBase.newKieSession();// 创建规则输出对象UserOut output = new UserOut();kieSession.setGlobal("output", output);// 创建规则输入对象UserIn input = new UserIn();input.setAge(19);// 执行规则kieSession.insert(input);// 指定流程idkieSession.startProcess("RFDemo");kieSession.fireAllRules();// 触发事件kieSession.signalEvent("None","2");kieSession.signalEvent("None","2");}

http://www.ppmy.cn/news/1474373.html

相关文章

Flink ui 本地flink ui 报错 {“errors“:[“Not found: /“]}

在学习flink 的过程中&#xff0c;伊始的flink 版本是1.17.2 报题目的错误 &#xff0c;百思不得其解&#xff0c;尝试更替了1.19.1 然后就成功了 &#xff0c;期间未做任何的修改 。 ui 默认地址 &#xff1a; http://localhost:8081 pom 文件 如下 <?xml version&qu…

MySQL安全值守常用语句

一、用户权限设置 1、Mysql中用户是如何定义的 用户名主机域 10.0.0.5110.0.0.%%10.0.0.0/255.255.255.0Db01Localhost127.0.0.1 2、用户创建 create user xinjing% identified by 123 3、用户删除 drop user username&#xff1b;username 是要删除的用户名:如 drop user root…

XSS 攻击是什么?如何防护?

1. 什么是 XSS 攻击 跨站脚本攻击&#xff0c;是一种很常见的网络安全威胁。 它允许攻击者在目标浏览器中注入恶意脚本代码。这些恶意脚本会执行多种非法操作。比如盗取你的 cookie&#xff0c;会话信息&#xff0c;篡改网页内容&#xff0c;重定向到别的恶意网站。控制浏览器…

k8s学习之cobra命令库学习

1.前言 打开k8s代码的时候&#xff0c;我发现基本上那几个核心服务都是使用cobra库作为命令行处理的能力。因此&#xff0c;为了对代码之后的代码学习的有比较深入的理解&#xff0c;因此先基于这个库写个demo&#xff0c;加深对这个库的一些理解吧 2.cobra库的基本简介 Git…

el-dropdown的command方法添加自定义参数

代码 <div v-for"(item, index) in queryParams.changeParams" :key"index"><el-form-item prop"dataConditionSearch"><el-dropdown command"handleCommand" style"margin-right: 3px;"><span class…

宪法学学习笔记(个人向) Part.3

宪法学学习笔记(个人向) Part 3 3. 国家基本制度 3.1 国家性质 3.1.1 国家性质概述 国家性质的概念 国家性质也称国体&#xff0c;或国家的阶级本质&#xff0c;是指各个阶级在国家中的地位&#xff08;哪个阶层是统治阶层&#xff0c;哪个阶层是被统治阶层&#xff0c;哪个…

Java中的类与对象

一、类 定义&#xff1a;对具有相同特征的这一类事物所进行的抽象描述 比如&#xff1a;人类 二、对象&#xff08;实例&#xff09; 定义&#xff1a;实际存在的该类事物的具体个体 比如&#xff1a;张三 三、定义类 编程是对现实生活中事物的体现&#xff0c;是对现实…

关于数组的常见算法

一、案例一 案例说明 案例&#xff1a;定义一个int型的一维数组&#xff0c;包含10个元素&#xff0c;分别赋一些随机整数&#xff0c;然后求出所有元素的最大值&#xff0c;最小值&#xff0c;总和&#xff0c;平均值&#xff0c;并输出出来 要求&#xff1a;所有随机数都是两…