smart-flow v1.1.0 发布,更低的接入成本

科技资讯 投稿 6700 0 评论

smart-flow v1.1.0 发布,更低的接入成本

1、smart-flow 简介

smart-flow 是一个轻量、灵活的业务流程编排框架,支持业务流程中常见的条件分支控制、子流程、业务组件异步和降级等功能。同时 smart-flow 也是一款具备可观测性的流程编排框架,流程结构拓扑、执行路径跟踪、链路分析等功能能帮助您洞察整个业务流程和执行。

smartboot 开源组织,一个容易被误认为是在 “重复造轮子” 的低调组织。曾获得 2020 年度 OSC 中国开源项目「优秀 Gitee 组织 」荣誉。

该组织内的明星项目包括:

    smart-socket
    历时 5 年精炼出 2 千多行代码,轻松实现百万级长连接的 AIO 通信框架。

  • smart-http
    基于 smart-socket 实现的 HTTP/1.1 web 服务。

  • smart-servlet
    基于 smart-http 实现的 Servlet 3.1 容器服务。

  • smart-mqtt

    基于 smart-socket 实现的 MQTT 3.1.1/5.0 Broker&Client 服务。
  • smart-flow
    一款具备可观测性的轻量级业务编排框架。

组织地址:https://smartboot.tech/
代码仓库:https://gitee.com/smartboot

2、 版本更新

v1.1.0 版本更新内容特性如下:

ExecutionListener新增SPI扩展方式

v1.0.9以前Listener生效需要开发者手动调用API进行注册,例如以下示例:

ExecutionListenerRegistry.register(new ExampleListener());

1.1.0以后,ExecutionListener新增支持Java标准SPI扩展方式,只需要在META-INF/serivices下新建以ExecutionListener全称限定类名为名称的文件,将需要注册的扩展类全称限定名配置到文件中即可生效
 

自定义绑定Executable属性

1.0.9以前,如果用户想要为Executable设置自定义属性,需要手动配置好属性后再将其设置到流程引擎中。例如以下示例

// 1、设置属性 JdbcExecutable je = new JdbcExecutable(); je.setDriverClass(""); je.setUrl(""); je.setUsername(""); je.setPassword(""); // 2、参与编排 Builders.pipeline() .... // 其他步骤 .next(je) .... // 其他步骤

这种方式使得xml编排方式受到了限制,所以在1.1.0版本中新增自定义属性绑定功能,上述代码可以转化为以下xml配置示例:

<pipeline name="example"> <component execute="JdbcExecutable" execute.driver-class="" execute.url="" execute.username="" execute.password="" /> </pipeline>

smart-flow默认情况下将execute.开头的属性视为需要为执行器Executable绑定的属性,通过setter和字段反射的方式进行属性设置。而关于属性的类型,smart-flow会根据setter或字段类型自动进行转换,如果转换失败则解析失败。更多文档参考 自定义Executable

 

功能增强插件

增强插件是基于核心包开发,用于增加smart-flow功能的模块。使用此模块可以降低接入成本,更多文档请阅读 增强插件。

<dependency> <groupId>org.smartboot.flow</groupId> <artifactId>smart-flow-enhance-plugin</artifactId> <version>${lastest.version}</version> </dependency>

增强插件目前提供3个功能

    反射执行器
  • shell执行器
  • 占位符替换功能 

以下示例代码演示反射执行器使用:

@Service public class CustomExecutable { public Object execute(Integer request, Integer result) { System.out.println("custom1 executed " + request + " result = " + result); return new Exception("hello, will passed by smart-flow engine."); } } @Service public class CustomExecutable2 { public static void execute(Integer request, int result, Exception customEx) { int a = 10; int b = 12; double d = 12; System.out.println("custom3 executed " + request + " result = " + result + " customExMsg = " + customEx.getMessage()); System.out.println(a + b + d); } }

业务流程分为2步,CustomExecutable接收出入参数,然后返回一个异常对象,然后CustomExecutable2接受出入参数以及步骤1中返回值异常对象。

<pipeline name="example"> <component execute="reflect" reflect.target="customExecutable" reflect.execute-method="execute" reflect.result-id="customEx"/> <component execute="reflect" reflect.target="customExecutable2" reflect.execute-method="execute"/> </pipelin>

以上配置使用了短语为reflect的反射执行器,为步骤1设置了执行目标customExecutable与执行方法execute,同时设置了返回值id为customEx, 步骤2设置与1同,区别在于未设置返回值id。

 

二进制执行包

二进制执行包基于增强插件开发,它作为一个新的尝试:在项目外解析并执行smart-flow的流程文件。

下载📎smart-flow-bootstrap-1.1.0.tar.gz解压后进入bin目录,并执行以下指令, 其中📎flow-example-simple-shell.xml为一个测试流程文件

./smart-flow.sh -f ../../flow-example-simple-shell.xml -t

执行后控制台可以观察到输出:

===================== start execute shell step1 ============================================ /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home ===================== end execute shell step1 ============================================ ===================== start execute shell step2 ============================================ hello world!!! ===================== end execute shell step2 ============================================ ===================== start execute shell step3 ============================================ a ===================== end execute shell step3 ============================================ invoke trace tree: flow-engine##testEngine escaped 27ms |--- subprocess1 escaped 27ms |--- shell@step1 escaped 14ms |--- shell@step2 escaped 5ms |--- shell@step3 escaped 5ms

如果流程文件中使用到了其他jar依赖,可以通过参数-cp或者-classpath 指定类路径。

其他更新

    layui-vue升级
  • 页面样式调整与流程图生成调整
  • 解析g6流程图生成xml格式优化

 

3、如何使用 smart-flow

3.1 源码

    主仓库:https://gitee.com/smartboot/smart-flow

3.2 Maven 依赖

    smart-flow-core 核心包,可单独使用

<dependency> <groupId>org.smartboot.flow</groupId> <artifactId>smart-flow-core</artifactId> <version>1.1.0</version> </dependency>

    smart-flow-spring-extension spring 扩展

<dependency> <groupId>org.smartboot.flow</groupId> <artifactId>smart-flow-spring-extension</artifactId> <version>1.1.0</version> </dependency>

    smart-flow-manager 管理功能包

<dependency> <groupId>org.smartboot.flow</groupId> <artifactId>smart-flow-manager</artifactId> <version>1.1.0</version> </dependency>

3.3 使用

点击查看快速接入

3.4、示例地址

demo 工程地址

管理控制台体验地址

 

编程笔记 » smart-flow v1.1.0 发布,更低的接入成本

赞同 (34) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽