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 源码

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 工程地址

管理控制台体验地址

 

优秀的个人博客,低调大师

微信关注我们

原文链接:https://www.oschina.net/news/246231/smart-flow-1-1-released

转载内容版权归作者及来源网站所有!

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

相关文章

发表评论

资源下载

更多资源
Mario,低调大师唯一一个Java游戏作品

Mario,低调大师唯一一个Java游戏作品

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Eclipse(集成开发环境)

Eclipse(集成开发环境)

Eclipse 是一个开放源代码的、基于Java的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse 附带了一个标准的插件集,包括Java开发工具(Java Development Kit,JDK)。

Java Development Kit(Java开发工具)

Java Development Kit(Java开发工具)

JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。

Sublime Text 一个代码编辑器

Sublime Text 一个代码编辑器

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。