Github:https://github.com/aceld/kis-flow
文档:https://github.com/aceld/kis-flow/wiki第 1 部分-概览
Part2.1-项目构建/基础模块
Part2.2-项目构建/基础模块
第三部分-数据流
Part4-功能调度
第5部分-连接器
Part6-配置导入导出
Part7-KisFlow 动作
Part8-Cache/Params 数据缓存和数据参数
Part9-流程的多份副本
Part10-Prometheus Metrics 统计
Part11-基于反射的FaaS参数类型自适应注册案例 1-快速入门
Case2-流程并行操作
Case3-KisFlow在多Goroutine中的应用下载 KisFlow 源代码
$前往 github.com/aceld/kis-flow
KisFlow 开发者文档
KisFlow 快速入门(使用配置文件) 源代码示例: kis-flow-usage/2-quick_start_with_config 位于 main · acld/kis-flow-usage首先,让我们创建一个具有以下文件结构的项目:
项目目录
├── Makefile
├── 会议
│ ├── flow-CalStuAvgScore.yml
│ ├── func-AvgStuScore.yml
│ └── func-PrintStuAvgScore.yml
├── faas_stu_score_avg.go
├── faas_stu_score_avg_print.go
└── main.go
流动
定义当前Flow。目前的Flow名为“CalStuAvgScore”,是一个计算学生平均成绩的数据流。
定义两个函数。 Function1是Calculate,是计算学生平均成绩的逻辑,Function2是Expand,是打印最终结果
配置
Flow 和 Functions 的配置文件如下:
(1) 流程配置 conf/flow-CalStuAvgScore.ymlkistype:流动
状态:1
flow_name:CalStuAvgScore
流量:
- 文件名称:AvgStuScore
- 文件名称:PrintStuAvgScore
conf/func-AvgStuScore.yml
kistype:功能
文件名称:AvgStuScore
fmode:计算
来源:
名称: 学生成绩
必须:
- 学生ID
conf/func-PrintStuAvgScore.yml
kistype:功能
文件名称:PrintStuAvgScore
fmode:展开
来源:
名称: 学生成绩
必须:
- 学生ID
主要的
接下来是主要逻辑,分为三步:
加载配置文件并获取Flow实例。 提交数据。 运行流程。main.go
包主
进口 (
“语境”
“FMMT”
“github.com/aceld/kis-flow/file”
“github.com/aceld/kis-flow/kis”
)
函数主() {
ctx := context.Background()
// 从文件加载配置
if err := file.ConfigImportYaml("conf/");错误!=零{
恐慌(错误)
}
// 获取流量
flow1 := kis.Pool().GetFlow("CalStuAvgScore")
如果流 1 == nil {
恐慌(“流1为零”)
}
// 提交字符串
_ = flow1.CommitRow(`{"stu_id":101, "score_1":100, "score_2":90, "score_3":80}`)
// 提交字符串
_ = flow1.CommitRow(`{"stu_id":102, "score_1":100, "score_2":70, "score_3":60}`)
// 运行流程
if err := flow1.Run(ctx);错误!=零{
fmt.Println("错误:",错误)
}
返回
}
功能1
第一个计算过程的实现逻辑如下。 AvgStuScoreIn 是输入数据类型,目前包含三个分数,AvgStuScoreOut 是输出数据类型,是平均分数。
faas_stu_score_avg.go
包主
进口 (
“语境”
“github.com/aceld/kis-flow/kis”
“github.com/aceld/kis-flow/serialize”
)
类型 AvgStuScoreIn 结构体 {
序列化.DefaultSerialize
StuId int `json:"stu_id"`
Score1 int `json:"score_1"`
Score2 int `json:"score_2"`
Score3 int `json:"score_3"`
}
类型 AvgStuScoreOut 结构体 {
序列化.DefaultSerialize
StuId int `json:"stu_id"`
AvgScore float64 `json:"avg_score"`
}
// AvgStuScore(FaaS) 计算学生的平均成绩
func AvgStuScore(ctx context.Context, flow kis.Flow, rows []AvgStuScoreIn) error {
对于 _, row := 范围行 {
输出 := AvgStuScoreOut{
StuId:行.StuId,
平均得分:float64(行.得分1+行.得分2+行.得分3) / 3,
}
// 提交结果数据
_ = flow.CommitRow(out)
}
返回零
}
功能2
打印的逻辑是直接打印数据,如下
faas_stu_score_avg_print.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
包主
进口 (
“语境”
“FMMT”
“github.com/aceld/kis-flow/kis”
“github.com/aceld/kis-flow/serialize”
)
类型 PrintStuAvgScoreIn 结构体 {
序列化.DefaultSerialize
StuId int `json:"stu_id"`
AvgScore float64 `json:"avg_score"`
}
类型 PrintStuAvgScoreOut 结构体 {
序列化.DefaultSerialize
}
func PrintStuAvgScore(ctx context.Context, flow kis.Flow, rows []PrintStuAvgScoreIn) error {
对于 _, row := 范围行 {
fmt.Printf("stuid: [%+v], 平均成绩: [%+v]n", row.StuId, row.AvgScore)
}
返回零
}
输出
最后运行程序,得到如下结果:
1
2
3
4
5
添加 KisPool FuncName=AvgStuScore
添加 KisPool FuncName=PrintStuAvgScore
添加 FlowRouter FlowName=CalStuAvgScore
学生:[101],平均分数:[90]
学习:[102],平均分数:[76.66666666666667]
2.KisFlow快速入门(使用原生接口,动态配置)
源代码示例:kis-flow-usage/1-quick_start at main · acld/kis-flow-usage
项目目录
1
2
3
├── faas_stu_score_avg.go
├── faas_stu_score_avg_print.go
└── main.go
流动
主要的
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
包主
进口 (
“语境”
“FMMT”
“github.com/aceld/kis-flow/common”
“github.com/aceld/kis-flow/config”
“github.com/aceld/kis-flow/flow”
“github.com/aceld/kis-flow/kis”
)
函数主() {
ctx := context.Background()
// 创建新的流配置
myFlowConfig1 := config.NewFlowConfig("CalStuAvgScore", common.FlowEnable)
// 创建新的函数配置
avgStuScoreConfig := config.NewFuncConfig("AvgStuScore", common.C, nil, nil)
printStuScoreConfig := config.NewFuncConfig("PrintStuAvgScore", common.E, nil, nil)
// 创建一个新流
flow1 := flow.NewKisFlow(myFlowConfig1)
// 将函数链接到流程
_ = flow1.Link(avgStuScoreConfig, nil)
_ = flow1.Link(printStuScoreConfig, nil)
// 提交字符串
_ = flow1.CommitRow(`{"stu_id":101, "score_1":100, "score_2":90, "score_3":80}`)
// 提交字符串
_ = flow1.CommitRow(`{"stu_id":102, "score_1":100, "score_2":70, "score_3":60}`)
// 运行流程
if err := flow1.Run(ctx);错误!=零{
fmt.Println("错误:",错误)
}
返回
}
函数初始化{
// 注册函数
kis.Pool().FaaS("AvgStuScore", AvgStuScore)
kis.Pool().FaaS("PrintStuAvgScore", PrintStuAvgScore)
}
功能1
faas_stu_score_avg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
包主
进口 (
“语境”
“github.com/aceld/kis-flow/kis”
“github.com/aceld/kis-flow/serialize”
)
类型 AvgStuScoreIn 结构体 {
序列化.DefaultSerialize
StuId int `json:"stu_id"`
Score1 int `json:"score_1"`
Score2 int `json:"score_2"`
Score3 int `json:"score_3"`
}
类型 AvgStuScoreOut 结构体 {
序列化.DefaultSerialize
StuId int `json:"stu_id"`
AvgScore float64 `json:"avg_score"`
}
// AvgStuScore(FaaS) 计算学生的平均成绩
func AvgStuScore(ctx context.Context, flow kis.Flow, rows []AvgStuScoreIn) error {
对于 _, row := 范围行 {
输出 := AvgStuScoreOut{
StuId:行.StuId,
平均得分:float64(行.得分1+行.得分2+行.得分3) / 3,
}
// 提交结果数据
_ = flow.CommitRow(out)
}
返回零
}
功能2
faas_stu_score_avg_print.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
包主
进口 (
“语境”
“FMMT”
“github.com/aceld/kis-flow/kis”
“github.com/aceld/kis-flow/serialize”
)
类型 PrintStuAvgScoreIn 结构 {
序列化.DefaultSerialize
StuId int `json:"stu_id"`
AvgScore float64 `json:"avg_score"`
}
类型 PrintStuAvgScoreOut 结构体 {
序列化.DefaultSerialize
}
func PrintStuAvgScore(ctx context.Context, flow kis.Flow, rows []PrintStuAvgScoreIn) error {
对于 _, row := 范围行 {
fmt.Printf("stuid: [%+v], 平均成绩: [%+v]n", row.StuId, row.AvgScore)
}
返回零
}
输出
1
2
3
4
5
6
添加 KisPool FuncName=AvgStuScore
添加 KisPool FuncName=PrintStuAvgScore
funcName NewConfig 源为零,funcName = AvgStuScore,使用默认的未命名源。
funcName NewConfig 源为零,funcName = PrintStuAvgScore,使用默认的未命名源。
学生:[101],平均分数:[90]
学习:[102],平均分数:[76.66666666666667]
作者:Aceld
GitHub:https://github.com/aceldKisFlow 开源项目地址:https://github.com/aceld/kis-flow
文档:https://github.com/aceld/kis-flow/wiki
第 1 部分-概览
Part2.1-项目构建/基础模块
Part2.2-项目构建/基础模块
第三部分-数据流
Part4-功能调度
第5部分-连接器
Part6-配置导入导出
Part7-KisFlow 动作
Part8-Cache/Params 数据缓存和数据参数
Part9-流程的多份副本
Part10-Prometheus Metrics 统计
Part11-基于反射的FaaS参数类型自适应注册案例 1-快速入门
Case2-Flow并行运行
Case3-KisFlow在多Goroutine中的应用以上就是案例 (一)-KisFlow-Golang流实时计算-快速入门指南的详细内容,更多请关注其它相关文章!