组件手动注册

对于组件来说,LiteFlow不光支持springboot/spring的扫描,还支持在规则文件里定义组件

除此之外,LiteFlow还支持代码式的组件注册,适用于一些特殊场景,比如代码中生成的动态代理类

假设有a,b两个组件

  1. public class ACmp extends NodeComponent {
  2. @Override
  3. public void process() {
  4. System.out.println("ACmp executed!");
  5. }
  6. }
  7. public class BCmp extends NodeComponent {
  8. @Override
  9. public void process() {
  10. System.out.println("BCmp executed!");
  11. }
  12. }

springboot环境

配置文件中一定要把parse-on-start设为false

  1. liteflow.rule-source=config/flow.xml
  2. liteflow.parse-on-start=false

Java代码

  1. FlowBus.addNode("a", ACmp.class);
  2. FlowBus.addNode("b", BCmp.class);
  3. LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request");

spring环境

  1. <context:component-scan base-package="com.yomahub.flowtest.components" />
  2. <bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
  3. <bean class="com.yomahub.liteflow.spring.ComponentScaner"/>
  4. <bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
  5. <property name="ruleSource" value="config/flow.xml"/>
  6. <property name="parseOnStart" value="false"/>
  7. </bean>
  8. <bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
  9. <property name="liteflowConfig" ref="liteflowConfig"/>
  10. </bean>
  11. <!-- 如果上述enableLog为false,下面这段也可以省略 -->
  12. <bean class="com.yomahub.liteflow.monitor.MonitorBus">
  13. <property name="liteflowConfig" ref="liteflowConfig"/>
  14. </bean>

Java代码

  1. FlowBus.addNode("a", ACmp.class);
  2. FlowBus.addNode("b", BCmp.class);
  3. LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request");