Basic Example

源代码: https://github.com/yomorun/yomo/tree/master/example/0-basic

这个例子展示了 YoMo 是如何使用噪声传感器的模拟数据的。

代码结构

  • source: 噪声传感器的模拟数据。
  • sfn: 实时检测噪声污染并在达到阈值时打印警告信息。
  • zipper: 协调一个工作流,从 source 接收数据,在stream-fn进行流计算。

如何运行这个例子

1. 安装 YoMo CLI

Binary(推荐)

$ curl -fsSL "https://get.yomo.run" | sh

或者从源代码编译

$ go install github.com/yomorun/cli/yomo@latest

2. 运行 zipper

yomo serve -c ./workflow.yaml

Using config file: ./workflow.yaml
2021/11/11 16:09:54 [yomo:zipper] [AddWorkflow] 0, Noise
ℹ️   Running YoMo-Zipper...
2021/11/11 16:09:54 [yomo:zipper] Listening SIGTERM/SIGINT...
2021/11/11 16:09:54 [core:server](name:Service) Listening on: 127.0.0.1:9000, QUIC: [v1 draft-29]

3. 运行 stream-function

go run ./sfn/main.go

2021/11/11 16:11:05 [core:client] use credential: [None]
2021/11

4. 运行 stream-fn-db

go run ./stream-fn-db/app.go -n MockDB

2021/05/20 14:10:29 ✅ Connected to zipper localhost:9000
2021/05/20 14:10:29 Running the Serverless Function.

5. 运行yomo-source

go run ./source/main.go

2021/11/11 16:12:01 [core:client] use credential: [None]
2021/11/11 16:12:01 [core:client] ❤️  [yomo-source] is connected to YoMo-Zipper localhost:9000
2021/11/11 16:12:01 [source] ✅ Emit {192.13399 1636618321242 localhost} to YoMo-Zipper
2021/11/11 16:12:01 [source] ✅ Emit {132.86566 1636618321547 localhost} to YoMo-Zipper
2021/11/11 16:12:01 [source] ✅ Emit {199.17604 1636618321851 localhost} to YoMo-Zipper

结果

stream-function

stream-function 的终端将打印实时噪声分贝值,并在数值达到阈值时显示警告。

2021/11/11 16:12:01 >> [sfn] got tag=0x33, data={ 0x1.80449ap+07  0x17d0e0dbd5a 0x6c 0x6f 0x63 0x61 0x6c 0x68 0x6f 0x73 0x74}
2021/11/11 16:12:01 >> [sfn] got tag=0x33, data={ 0x1.09bb38p+07  0x17d0e0dbe8b 0x6c 0x6f 0x63 0x61 0x6c 0x68 0x6f 0x73 0x74}
2021/11/11 16:12:01 >> [sfn] got tag=0x33, data={ 0x1.8e5a22p+07  0x17d0e0dbfbb 0x6c 0x6f 0x63 0x61 0x6c 0x68 0x6f 0x73 0x74}
在 GitHub 上编辑本页面 更新时间: Mon, Aug 1, 2022