介绍
- 1: Dapr介绍
- 2: 概述
- 2.1: Dapr的构建
- 2.2: Dapr的命令行参数
- 3: Quickstart
- 3.1: 安装 dapr
- 3.2: Hello World
- 4: 资料收集
1 - Dapr介绍
Dapr是什么?
Dapr 是 Distributed Application Runtime (分布式应用运行时)的缩写。
Dapr github首页的介绍是:
Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.
Dapr是一种可移植的,事件驱动的运行时,用于构建跨云和边缘的分布式应用。
号称可以:
Any language, any framework, anywhere
详细介绍是:
Dapr是一种可移植的,serverless的,事件驱动的运行时,它使开发人员可以轻松构建弹性,无状态和有状态微服务,这些服务运行在云和边缘上,并包含多种语言和开发框架。
Dapr 整理了构建微服务应用为开放,独立的构建块的最佳实践,使您能够使用自己选择的语言和框架来构建可移植的应用程序。 每个构建块都是独立的,您可以在应用中使用其中的一个或多个。
注意:Dapr目前正处于社区开发中的 Alpha 阶段。 在其1.0稳定版本发布之前,不要将 Dapr 用于生产工作负载。
下图是 Dapr 的概念模型:
以下内容来自:https://github.com/dapr/dapr
目标
- 使开发人员能够使用任何语言或框架来编写分布式应用
- 通过提供最佳实践构建模块来解决开发人员构建微服务应用时面临的难题
- 社区驱动,开放,供应商无关
- 获得新的贡献者
- 通过开放的API提供一致性和可移植性
- 跨云和边缘,与平台无关
- 拥抱可扩展性并提供可插入组件,而无需供应商锁定
- 通过高性能和轻量级实现物联网(IoT)和边缘场景
- 可以从现有代码中逐步采用,而没有运行时依赖
工作方式
Dapr向每个计算单元注入了一个Sidecar容器/进程。Sidecar与事件触发器进行交互,并通过标准HTTP或gRPC协议与计算单元进行通信。这使Dapr能够支持所有现有和将来的编程语言,而无需您导入框架或库。
Dapr通过标准的HTTP verbs 或gRPC interface 提供内置的状态管理,可靠消息传递(至少一次传递),触发器和绑定。这使您可以遵循相同的编程范例编写无状态,有状态和类似于actor的服务。您可以自由选择一致性模型,线程模型和消息传递模式。
Dapr在Kubernetes上原生运行,也可以作为机器上的独立二进制文件,在IoT设备上运行,也可以作为容器注入到任何系统中,无论是在云端还是在本地。
Dapr使用可插拔状态存储和消息总线(例如Redis)以及gRPC来提供广泛的通信方法,包括使用gRPC的直接 dapr-to-dapr 通讯和具有保证传递和至少一次语义的异步Pub-Sub。
为什么用 Dapr?
编写高性能,可伸缩和可靠的分布式应用很困难。 Dapr带给您成熟的模式和实践。 它将事件驱动和 actor 的语义统一到一个简单而一致的编程模型中。 它支持所有编程语言,没有框架锁定。 您不会接触到低级原语,例如线程,并发控制,分区和伸缩。 相反,您可以通过使用所选的熟悉的Web框架实现简单的Web服务器来编写代码。
Dapr在线程和状态一致性模型方面很灵活。 如果愿意,可以利用多线程,还可以在不同的一致性模型中进行选择。 这种灵活性使得无需人为约束即可实施高级方案。 您可能还选择利用其他Actor框架中熟悉的单线程调用。 Dapr是独一无二的,因为您可以在这些模型之间无缝转换而无需重写代码。
特性
- 事件驱动的Pub-Sub系统,具有可插拔提供商和至少一次的语义
- 输入和输出绑定,使用可插拔提供商
- 具有可插拔数据存储的状态管理
- 一致的服务到服务发现和调用
- 选择加入状态模型:强大/最终的一致性,首次写入/最后写入获胜
- 跨平台虚拟 actor
- 密钥管理,从安全密钥库中提取密钥。
- 限速
- 内置可观测性支持
- 使用专用的Operator和CRD在Kubernetes上原生运行
- 通过HTTP和gRPC支持所有编程语言
- 来自Azure,AWS,GCP的多云,开放式组件(绑定,发布-订阅,状态)
- 在任何地方运行,无论是进程还是容器化
- 轻量级(58MB二进制,4MB物理内存)
- 作为Sidecar运行-无需特殊的SDK或类库
- 专用的CLI-开发人员友好的体验,易于调试
- Java,.NET Core,Go,Javascript,Python,Rust和C ++的客户端
2 - 概述
2.1 - Dapr的构建
build
在项目根目录下执行 :
$ make build
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X github.com/dapr/dapr/pkg/version.commit=v0.8.0-rc.2-96-g79a1f14 -X github.com/dapr/dapr/pkg/version.version=edge -s -w" -o ./dist/darwin_amd64/release/daprd ./cmd/daprd/main.go;
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X github.com/dapr/dapr/pkg/version.commit=v0.8.0-rc.2-96-g79a1f14 -X github.com/dapr/dapr/pkg/version.version=edge -s -w" -o ./dist/darwin_amd64/release/placement ./cmd/placement/main.go;
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X github.com/dapr/dapr/pkg/version.commit=v0.8.0-rc.2-96-g79a1f14 -X github.com/dapr/dapr/pkg/version.version=edge -s -w" -o ./dist/darwin_amd64/release/operator ./cmd/operator/main.go;
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X github.com/dapr/dapr/pkg/version.commit=v0.8.0-rc.2-96-g79a1f14 -X github.com/dapr/dapr/pkg/version.version=edge -s -w" -o ./dist/darwin_amd64/release/injector ./cmd/injector/main.go;
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X github.com/dapr/dapr/pkg/version.commit=v0.8.0-rc.2-96-g79a1f14 -X github.com/dapr/dapr/pkg/version.version=edge -s -w" -o ./dist/darwin_amd64/release/sentry ./cmd/sentry/main.go;
构建完成之后得到的文件:
$ ls -lh ./dist/darwin_amd64/release/
total 429128
-rwxr-xr-x 1 aoxiaojian staff 89M Aug 13 17:19 daprd
-rwxr-xr-x 1 aoxiaojian staff 33M Aug 13 17:20 injector
-rwxr-xr-x 1 aoxiaojian staff 35M Aug 13 17:20 operator
-rwxr-xr-x 1 aoxiaojian staff 12M Aug 13 17:19 placement
-rwxr-xr-x 1 aoxiaojian staff 33M Aug 13 17:20 sentry
2.2 - Dapr的命令行参数
name | default value | 可选值 | 说明 |
---|---|---|---|
mode | standalone | standalone / kubernetes | Runtime mode for Dapr |
dapr-http-port | 3500 | HTTP port for Dapr API to listen on | |
dapr-grpc-port | 50001 | gRPC port for the Dapr API to listen on | |
dapr-internal-grpc-port | "" | gRPC port for the Dapr Internal API to listen on 如果不指定,则dapr会自动获取一个随机可用的空闲端口 |
|
app-port | "" | The port the application is listening on 如果不设置,则不能建立dapr和应用之间的 app channel 也就意味着dapr 无法发送请求给应用了 同时dapr也无法从应用读取配置: http://localhost:<app_port>/dapr/config 注意:app的地址在代码中写死 127.0.0.1 |
|
profile-port | 7777 | The port for the profile server | |
app-protocol | http | http / grpc | Protocol for the application: grpc or http |
components-path | "" | Path for components directory. If empty, components will not be loaded. Self-hosted mode only 仅在dapr mode为standalone时有效 |
|
config | "" | Path to config file, or name of a configuration object 被称为 global configuration 如果是kubernetes mode,读取k8s的配置 如果是standalone mode,读取配置文件 如果没有配置,则装载默认配置 |
|
app-id | "" | A unique ID for Dapr. Used for Service Discovery and state | |
control-plane-address | "" | Address for a Dapr control plane 仅在dapr mode为kubernetes时有效 |
|
sentry-address | "" | Address for the Sentry CA service | |
placement-host-address | "" | Address for the Dapr placement service | |
allowed-origins | * |
Allowed HTTP origins | |
enable-profiling | false | True / false | Enable profiling |
version | false | True / false | Prints the runtime version (然后dapr就会退出) |
app-max-concurrency | -1 | Controls the concurrency level when forwarding requests to user code | |
enable-mtls | false | True / false | Enables automatic mTLS for daprd to daprd communication channels |
1.0 之后被弃用的flag:
name | 说明 |
---|---|
placement-address | 改为 placement-host-address 如果同时设置,以 placement-host-address 为准 |
max-concurrency | 改为 app-max-concurrency 如果同时设置,以 app-max-concurrency 为准 |
protocol | 改为 app-protocol 如果同时设置,以 app-protocol 为准 |
-app-id hellogrpc -app-port 3000 -protocol grpc -dapr-http-port 3005 -dapr-grpc-port 52000 -placement-address localhost:50005 -components-path components
3 - Quickstart
3.1 - 安装 dapr
安装 dapr
安装 dapr CLI
TBD
初始化 dapr
此时如果直接用 dapr run 命令启动应用和 sidecar,会报错:
$ dapr run --app-id invokedemo --app-port 3000 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.http.DemoService -p 3000
ℹ️ Starting Dapr with id invokedemo. HTTP Port: 42127. gRPC Port: 44623
❌ fork/exec /home/sky/.dapr/bin/daprd: no such file or directory
这是因为 daprd 等二进制文件还没有安装,需要执行 dapr init
先初始化安装 dapr:
$ dapr init
⌛ Making the jump to hyperspace...
ℹ️ Installing runtime version 1.6.0
❌ Downloading binaries and setting up components...
❌ error downloading dashboard binary: Get "https://github.com/dapr/dashboard/releases/download/v0.9.0/dashboard_linux_amd64.tar.gz": unexpected EOF
很不幸的是这个命令是直接从 github 网站下载,经常出现问题,无法连接或者下载中途中断。最好是先把科学上网的代理设置好,再执行:
$ dapr init
⌛ Making the jump to hyperspace...
ℹ️ Installing runtime version 1.6.0
→ Downloading binaries and setting up components...
Dapr runtime installed to /home/sky/.dapr/bin, you may run the following to add it to your path if you want to run daprd directly:
export PATH=$PATH:/home/sky/.dapr/bin ✅ Downloading binaries and setting up components...
✅ Downloaded binaries and completed components set up.
ℹ️ daprd binary has been installed to /home/sky/.dapr/bin.
ℹ️ dapr_placement container is running.
ℹ️ dapr_redis container is running.
ℹ️ dapr_zipkin container is running.
ℹ️ Use `docker ps` to check running containers.
✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
3.2 - Hello World
参考官方文档
https://github.com/dapr/quickstarts/tree/master/hello-world
安装dapr
准备工作
按照 Prerequisites 的要求安装:
-
docker
-
ubuntu 安装方法:https://docs.docker.com/engine/install/ubuntu/
- mac 安装方法:
brew cask install docker
(执行前先开启一下代理,否则速度很慢),完成后启动docker程序会继续安装。
- mac 安装方法:
-
nodejs
# ubuntu下 sudo apt update sudo apt install nodejs npm # mac下 brew install nodejs
-
python3.8:
- ubuntu 20.04自带
- macos自带
安装并初始化dapr
https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#environment-setup
按照文档指导可以在本地跑起来dapr和两个应用 nodejs app 和 pythonapp。
运行应用和dapr
启动 nodeapp:
$ dapr run --app-id nodeapp --app-port 3000 --port 3500 node app.js
ℹ️ Starting Dapr with id nodeapp. HTTP Port: 3500. gRPC Port: 41313
== DAPR == time="2020-08-13T03:01:27.401563329Z" level=info msg="starting Dapr Runtime -- version 0.9.0 -- commit 6babe85-dirty" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.401592638Z" level=info msg="log level set to: info" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.403754652Z" level=info msg="metrics server started on :45301/" app_id=nodeapp instance=server-22 scope=dapr.metrics type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.40608922Z" level=info msg="standalone mode configured" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.406101799Z" level=info msg="app id: nodeapp" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.406109449Z" level=info msg="mTLS is disabled. Skipping certificate request and tls validation" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.406491465Z" level=info msg="found component zipkin (exporters.zipkin)" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.406815324Z" level=info msg="found component pubsub (pubsub.redis)" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.406827704Z" level=info msg="found component statestore (state.redis)" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.406836693Z" level=info msg="application protocol: http. waiting on port 3000. This will block until the app is listening on that port." app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== APP == Node App listening on port 3000!
== DAPR == time="2020-08-13T03:01:27.6668991Z" level=info msg="application discovered on port 3000" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.676719603Z" level=info msg="application configuration loaded" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.683106449Z" level=info msg="local service entry announced: nodeapp -> 192.168.0.22:40147" app_id=nodeapp instance=server-22 scope=dapr.contrib type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.683134018Z" level=info msg="Initialized name resolution to standalone" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.684083474Z" level=info msg="actor runtime started. actor idle timeout: 1h0m0s. actor scan interval: 30s" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.684125533Z" level=info msg="enabled monitoring middleware" app_id=nodeapp instance=server-22 scope=dapr.runtime.grpc.api type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.684147342Z" level=info msg="API gRPC server is running on port 41313" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.684159811Z" level=info msg="enabled monitoring middleware" app_id=nodeapp instance=server-22 scope=dapr.runtime.grpc.internal type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.68419098Z" level=info msg="internal gRPC server is running on port 40147" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.68447814Z" level=info msg="enabled cors http middleware" app_id=nodeapp instance=server-22 scope=dapr.runtime.http type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.684526578Z" level=info msg="enabled metrics http middleware" app_id=nodeapp instance=server-22 scope=dapr.runtime.http type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.684532368Z" level=info msg="enabled tracing http middleware" app_id=nodeapp instance=server-22 scope=dapr.runtime.http type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.685153897Z" level=info msg="http server is running on port 3500" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.685141747Z" level=info msg="starting connection attempt to placement service at localhost:50005" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.68675419Z" level=info msg="dapr initialized. Status: Running. Init Elapsed 280.688959ms" app_id=nodeapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.690870475Z" level=info msg="established connection to placement service at localhost:50005" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.695620718Z" level=info msg="placement order received: lock" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.695656467Z" level=info msg="placement order received: update" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.695664007Z" level=info msg="actors: placement tables updated" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T03:01:27.695696185Z" level=info msg="placement order received: unlock" app_id=nodeapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
ℹ️ Updating metadata for app command: node app.js
✅ You're up and running! Both Dapr and your app logs will appear here.
启动 pythonapp:
$ dapr run --app-id pythonapp python3 app.py
ℹ️ Starting Dapr with id pythonapp. HTTP Port: 36919. gRPC Port: 45173
== APP == HTTPConnectionPool(host='localhost', port=36919): Max retries exceeded with url: /v1.0/invoke/nodeapp/method/neworder (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1bd71669d0>: Failed to establish a new connection: [Errno 111] Connection refused'))
== DAPR == time="2020-08-13T06:46:56.72406294Z" level=info msg="starting Dapr Runtime -- version 0.9.0 -- commit 6babe85-dirty" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.72409239Z" level=info msg="log level set to: info" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.72418481Z" level=info msg="metrics server started on :46033/" app_id=pythonapp instance=server-22 scope=dapr.metrics type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.724529889Z" level=info msg="standalone mode configured" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.724553109Z" level=info msg="app id: pythonapp" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.724569429Z" level=info msg="mTLS is disabled. Skipping certificate request and tls validation" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.724949349Z" level=info msg="found component zipkin (exporters.zipkin)" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.724973299Z" level=info msg="found component pubsub (pubsub.redis)" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.724978979Z" level=info msg="found component statestore (state.redis)" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726339857Z" level=info msg="local service entry announced: pythonapp -> 192.168.0.22:41923" app_id=pythonapp instance=server-22 scope=dapr.contrib type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726362247Z" level=info msg="Initialized name resolution to standalone" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726380477Z" level=error msg="failed to init input bindings: app channel not initialized" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726423417Z" level=info msg="actor runtime started. actor idle timeout: 1h0m0s. actor scan interval: 30s" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726447457Z" level=info msg="enabled monitoring middleware" app_id=pythonapp instance=server-22 scope=dapr.runtime.grpc.api type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726464967Z" level=info msg="API gRPC server is running on port 45173" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726585237Z" level=info msg="enabled monitoring middleware" app_id=pythonapp instance=server-22 scope=dapr.runtime.grpc.internal type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726699017Z" level=info msg="internal gRPC server is running on port 41923" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726787137Z" level=info msg="enabled cors http middleware" app_id=pythonapp instance=server-22 scope=dapr.runtime.http type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726817007Z" level=info msg="enabled metrics http middleware" app_id=pythonapp instance=server-22 scope=dapr.runtime.http type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726821527Z" level=info msg="enabled tracing http middleware" app_id=pythonapp instance=server-22 scope=dapr.runtime.http type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726828177Z" level=info msg="http server is running on port 36919" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726836537Z" level=info msg="dapr initialized. Status: Running. Init Elapsed 2.306748ms" app_id=pythonapp instance=server-22 scope=dapr.runtime type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.726891147Z" level=info msg="starting connection attempt to placement service at localhost:50005" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.727357086Z" level=info msg="established connection to placement service at localhost:50005" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.727944425Z" level=info msg="placement order received: lock" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.727973365Z" level=info msg="placement order received: update" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.727980025Z" level=info msg="actors: placement tables updated" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
== DAPR == time="2020-08-13T06:46:56.727986475Z" level=info msg="placement order received: unlock" app_id=pythonapp instance=server-22 scope=dapr.runtime.actor type=log ver=0.9.0
ℹ️ Updating metadata for app command: python3 app.py
✅ You're up and running! Both Dapr and your app logs will appear here.
观察
进程信息
dapr 的组件以容器的方式运行,包括 zipkin / dapr(placement) / redis 三个容器:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c5fd90abf99 openzipkin/zipkin "/bin/sh -c /zipkin/…" 46 hours ago Up 4 hours (healthy) 9410/tcp, 0.0.0.0:9411->9411/tcp dapr_zipkin
f9edd8935e51 daprio/dapr "./placement" 46 hours ago Up 4 hours 0.0.0.0:50005->50005/tcp dapr_placement
70c1865d94b2 redis "docker-entrypoint.s…" 46 hours ago Up 4 hours 0.0.0.0:6379->6379/tcp dapr_redis
对象的docker镜像情况:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
openzipkin/zipkin latest 13a9766380f5 7 days ago 157MB
redis latest 1319b1eaa0b7 8 days ago 104MB
daprio/dapr latest 775fe3438f2b 3 weeks ago 189MB
node app 和 nodeapp 的 daprd(parent 进程是pythonapp):
$ dapr run --app-id nodeapp --app-port 3000 --port 3500 node app.js
$ ps -ef | grep nodeapp
sky 81337 65485 0 06:45 pts/0 00:00:00 dapr run --app-id nodeapp --app-port 3000 --port 3500 node app.js
sky 81354 81337 0 06:45 pts/0 00:00:00 daprd --app-id nodeapp --dapr-http-port 3500 --dapr-grpc-port 33575 --log-level info --max-concurrency -1 --protocol http --metrics-port 35191 --components-path /home/sky/.dapr/components --app-port 3000 --placement-address localhost:50005 --config /home/sky/.dapr/config.yaml
pythonapp 和 pythonapp 的 daprd(parent 进程是pythonapp):
$ dapr run --app-id pythonapp python3 app.py
$ ps -ef | grep pythonapp
sky 81698 80792 0 06:46 pts/3 00:00:00 dapr run --app-id pythonapp python3 app.py
sky 81715 81698 0 06:46 pts/3 00:00:00 daprd --app-id pythonapp --dapr-http-port 36919 --dapr-grpc-port 45173 --log-level info --max-concurrency -1 --protocol http --metrics-port 46033 --components-path /home/sky/.dapr/components --placement-address localhost:50005 --config /home/sky/.dapr/config.yaml
注意 daprd 启动了两个进程,分别服务于 pythonapp 和 nodeapp:
$ ps -ef | grep daprd
sky 81354 81337 0 06:45 pts/0 00:00:00 daprd --app-id nodeapp --dapr-http-port 3500 --dapr-grpc-port 33575 --log-level info --max-concurrency -1 --protocol http --metrics-port 35191 --components-path /home/sky/.dapr/components --app-port 3000 --placement-address localhost:50005 --config /home/sky/.dapr/config.yaml
sky 81715 81698 0 06:46 pts/3 00:00:00 daprd --app-id pythonapp --dapr-http-port 36919 --dapr-grpc-port 45173 --log-level info --max-concurrency -1 --protocol http --metrics-port 46033 --components-path /home/sky/.dapr/components --placement-address localhost:50005 --config /home/sky/.dapr/config.yaml
为了避免端口冲突,两个 dapr 进程的各种端口是不一样的。
dapr配置信息
$ cd ~/.dapr/
$ ls -lah
total 80M
drwxrwxrwx 3 sky sky 4.0K Aug 13 07:02 .
drwxr-xr-x 9 sky sky 4.0K Aug 13 07:02 ..
drwxrwxrwx 2 sky sky 4.0K Aug 13 07:00 components
-rw-r--r-- 1 sky sky 117 Aug 11 08:33 config.yaml
-rwxr-xr-x 1 sky sky 80M Aug 11 08:34 daprd
其中 daprd 是一个 80M 大小的可执行文件。
config.yaml 文件的内容:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprConfig
spec:
tracing:
samplingRate: "1"
/home/sky/.dapr/components 下的文件有:
$ ls /home/sky/.dapr/components
pubsub.yaml statestore.yaml zipkin.yaml
其中 pubsub.yaml 文件的内容为:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: pubsub
spec:
type: pubsub.redis
metadata:
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
state store.xml 的内容为:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.redis
metadata:
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
- name: actorStateStore
value: "true"
zipkin.xml 的内容为:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: zipkin
spec:
type: exporters.zipkin
metadata:
- name: enabled
value: "true"
- name: exporterAddress
value: http://localhost:9411/api/v2/spans
4 - 资料收集
官方网站
社区
- dapr-cn :Dapr中文社区,专注于dapr的文档、新闻稿本地化、新特性贡献以及中文社区推广
- Dapr 中文文档库: Dapr 中文文档库,由 dapr-cn 创建并维护的对 docs.dapr.io 内容的翻译,旨在为更熟悉中文的开发者提供一些文档上的帮助。
备注:由于dapr翻译计划已经启动,我也参与其中,我在学习笔记中翻译的部分官方文档内容都将陆续迁移过去,之后会删除学习笔记中的官方文档翻译内容。
文档
文章&演讲
介绍性的文章:
- Announcing Distributed Application Runtime (Dapr), an open source project to make it easier for every developer to build microservice applications: 2019-10-16
- 重磅!微软开源微服务构建软件 Dapr: 2019-10-17,上文的中文翻译。
- 2020年第一次技术沙龙——体验新云原生技术OAM&DAPR: 2020-01-12,参会介绍,有不少有见地的个人想法和见解,值得一读。
实践性的文章:
- Simplifying Microservices on Kubernetes with Microsoft’s Dapr: 2019-11-08,写的很细致
视频
- TGI Kubernetes 105: Dapr - Distributed Application Runtime: 2020-02-14
- OAM&Dapr-Dapr 简介-如何帮助开发者轻松构建应用程序: 2020-02-13
- Dapr - Distributed Application Runtime - An event-driven portable runtime for | MLS1070: 2020-01-15
- Mark Russinovich Presents the Future of Cloud Native Applications with OAM and dapr | BRK3098: 2020-01-14
- Dapr, Rudr, OAM | Mark Russinovich presents next gen app development & deployment (Microsoft Ignite): 2019-11-14
- Learn all about Distributed Application Runtime (Dapr), Part 1 | Azure Friday: 2019-10-25
相关资料
- The Evolution of Distributed Systems on Kubernetes : Bilgin Ibryam, 讲的极好。强烈推荐
- https://www.slideshare.net/AbhishekGupta126/tour-of-dapr?from_action=save
- The evolution of Distributed Systems: 另一个总结分布式系统演进的文章,比较全面,有很多典型的图片。