组件手动注册
对于组件来说,LiteFlow不光支持springboot/spring的扫描,还支持在规则文件里定义组件
除此之外,LiteFlow还支持代码式的组件注册,适用于一些特殊场景,比如代码中生成的动态代理类
假设有a,b两个组件
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}
springboot环境
配置文件中一定要把parse-on-start设为false
liteflow.rule-source=config/flow.xml
liteflow.parse-on-start=false
Java代码
FlowBus.addNode("a", ACmp.class);
FlowBus.addNode("b", BCmp.class);
LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request");
spring环境
<context:component-scan base-package="com.yomahub.flowtest.components" />
<bean id="springAware" class="com.yomahub.liteflow.util.SpringAware"/>
<bean class="com.yomahub.liteflow.spring.ComponentScaner"/>
<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
<property name="ruleSource" value="config/flow.xml"/>
<property name="parseOnStart" value="false"/>
</bean>
<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
<property name="liteflowConfig" ref="liteflowConfig"/>
</bean>
<!-- 如果上述enableLog为false,下面这段也可以省略 -->
<bean class="com.yomahub.liteflow.monitor.MonitorBus">
<property name="liteflowConfig" ref="liteflowConfig"/>
</bean>
Java代码
FlowBus.addNode("a", ACmp.class);
FlowBus.addNode("b", BCmp.class);
LiteflowResponse<DefaultSlot> response= flowExecutor.execute2Resp("chain1", "it's a request");