微软开源分布式系统运行时Dapr是什么,什么用,怎么用?

网友投稿 256 2022-09-10

微软开源分布式系统运行时Dapr是什么,什么用,怎么用?

官网实在太烂了,翻译的很痛苦,各位自己看吧。一下将整理为解析。

​​is a portable, event-driven runtime that makes it easy for any developer to build resilient, stateless and stateful applications that run on the cloud and edge and embraces the diversity of languages and developer frameworks.Dapr是运行时,因为其事件驱动和可移植特点,使得使用任何语言、任何框架的开发人员都可以轻松的开发并运行在云服务器上或边缘节点上的的弹性的、无状态的或有状态的应用程序。

无论你是现在的程序是什么语言、什么框架,是有状态的或无状态的,都可以用Dapr来构建分布式系统。

Today we are experiencing a wave of cloud adoption. Developers are comfortable with web + database application architectures, for example classic 3-tier designs, but not with microservice application architectures which are inherently distributed. It’s hard to become a distributed systems expert, nor should you have to. Developers want to focus on business logic, while leaning on the platforms to imbue their applications with scale, resiliency, maintainability, elasticity and the other attributes of cloud-native architectures.开发人员对经典的三层设计,web加数据库的应用程序框架是非常熟练和满意的,因为我们不用过多的关注其他事情,可以快速上手,更专注于业务逻辑。可是对于现在的云计算大环境,我们不得不考虑(有时是无需求的)学习或掌握如何开发和部署运维一个分布式的微服务系统。但是,这些不是我们开发人员应该考虑的事情。开发人员就是应该更关注业务逻辑,把部署和运维交给平台来做,让平台来做扩展性、弹性、可维护性、和其他属性。

当我们想开发分布式或微服务应用程序的时候,总是难免会陷入如何做日志、做服务发现、服务注册、如何维护、弹性扩展的问题上来。迟迟不能进入到真正的业务中来。

This is where Dapr comes in. Dapr codifies the best practices for building microservice applications into open, independent APIs called building blocks, that enable you to build portable applications with the language and framework of your choice. Each building block is completely independent and you can use one, some, or all of them in your application.Dapr就是为了解决这个问题而来的。Dapr将解决构建微服务系统的功能模块叫做 BuildingBlocks ,每个building block完全独立,有自己的开放API,通过BuildingBlocks 为我们提供,我们可以通过Dapr you can incrementally migrate your existing applications to a microservices architecture, thereby adopting cloud native patterns such scale out/in, resiliency and independent deployments.使用Dapr,可以将你的应用程序逐步迁移到微服务架构,采用云原生的模式,提供了横向扩展、弹性扩展、服务独立部署等能力。

是的,将云原生应用理解为部署在云服务器上的微服务应用程序加上各种平台提供的扩展监控能力等的一整套系统就可以了。

In addition, Dapr is platform agnostic, meaning you can run your applications locally, on any Kubernetes cluster, on virtual or physical machines and in other hosting environments that Dapr integrates with. This enables you to build microservice applications that can run on the cloud and edge.Dapr与平台无关,你可以在本地、K8s集群上、虚拟机、物理机及安装了Dapr的其他环境上运行应用程序。

微服务BuildingBlocks

要使用Dapr,就得先了解它给我们提供了哪些功能。一下将BuildingBlocks成为构建块。

上图每个构建块都可以独立部署和使用。

Building Block

Description

Service-to-service invocation(服务间调用)

Resilient service-to-service invocation enables method calls, including retries, on remote services, wherever they are located in the supported hosting environment.

服务间调用功能允许对远程服务的方法调用,包含重试功能,不用关心该服务唯一环境中的哪个位置。(服务发现)

State management(状态管理)

With state management for storing and querying key/value pairs, long-running, highly available, stateful services can be easily written alongside stateless services in your application. The state store is pluggable and examples include AWS DynamoDB, Azure CosmosDB, Azure SQL Server, GCP Firebase, PostgreSQL or Redis, among others.

状态存储功能,提供了键值对的查询方式。提供有状态的、长时间运行的、高可用的有状态服务,并且可选存储方式:redis、sql server等等。在无状态服务中的编写查询、更改有状态的数据存储变得很简单。

Publish and subscribe(发布与订阅)

Publishing events and subscribing to topics between services enables event-driven architectures to simplify horizontal scalability and make them resilient to failure. Dapr provides at-least-once message delivery guarantee, message TTL, consumer groups and other advance features.

事件驱动,发布订阅模式。提供服务间异步沟通的能力,简化水平扩展能力。Dapr提供了消息可靠性保障等消息队列该有的高级功能。

Resource bindings(资源绑定)

Resource bindings with triggers builds further on event-driven architectures for scale and resiliency by receiving and sending events to and from any external source such as databases, queues, file systems, etc.

资源绑定构建块可以任何外部资源进行事件的发送和接收,这样可以更好的构建事件驱动型应用程序,方便弹性扩展。

Actors(参与者模式)

A pattern for stateful and stateless objects that makes concurrency simple, with method and state encapsulation. Dapr provides many capabilities in its actor runtime, including concurrency, state, and life-cycle management for actor activation/deactivation, and timers and reminders to wake up actors.

参与者模式使得我们可以简单的处理并发。Dapr中的Actor提供了很多能力,包括并发,状态和生命周期管理。


Observability(可观测性)

Dapr emits metrics, logs, and traces to debug and monitor both Dapr and user applications. Dapr supports distributed tracing to easily diagnose and serve inter-service calls in production using the W3C Trace Context standard and Open Telemetry to send to different monitoring tools.

这个构建块支持分布式跟踪,用来调试和监控dapr和用户应用程序。

Secrets(密钥)

The secrets management API integrates with public cloud and local secret stores to retrieve the secrets for use in application code.

这个构建块提供密钥管理API,支持云端和本地密钥存储。

Configuration(配置)

The configuration API enables you to retrieve and subscribe to application configuration items from configuration stores.

这个构建块提供获取、订阅应用程序配置项的API。

Sidecar 架构

Dapr exposes its HTTP and gRPC APIs as a sidecar architecture, either as a container or as a process, not requiring the application code to include any Dapr runtime code. This makes integration with Dapr easy from other runtimes, as well as providing separation of the application logic for improved supportability.Dapr是一个Sidecar架构的实现,用户应用程序通过Dapr暴露的HTTP和gRPC接口与其进行沟通,意味着用户应用程序不需要包含任何Dapr相关的代码。

宿主机环境

Dapr can be hosted in multiple environments, including self-hosted on a Windows/Linux/macOS machines for local developement and on Kubernetes or clusters of physical or virtual machines in production.Dapr可以托管在多种环境中运行,包括自托管在Windows/Linux/macOS上用于本地开发,也可以在Kubernetes或生产环境中的物理或虚拟机集群上。

本地自托管

In ​​self-hosted mode​​ Dapr runs as a separate sidecar process which your service code can call via HTTP or gRPC. Each running service has a Dapr runtime process (or sidecar) which is configured to use state stores, pub/sub, binding components and the other building blocks.在自托管模式下,Dapr将作为一个独立的进程运行在宿主机上,应用程序代码可以通过HTTP或gRPC调用Dapr的功能模块。

Kubernetes 托管

Kubernetes can be used for either local development (for example with ​​minikube​​​, ​​k3S​​​) or in ​​production​​. In container hosting environments such as Kubernetes, Dapr runs as a sidecar container with the application container in the same pod.Kubernetes既可以用于本地开发(minikube,k3s),也可用于生产。在容器托管环境(Kubernetes)中,Dapr和应用程序运行在一个pod中Dapr has control plane services. The ​​dapr-sidecar-injector​​​ and ​​dapr-operator​​ services provide first-class integration to launch Dapr as a sidecar container in the same pod as the service container and provide notifications of Dapr component updates provisioned in the cluster.Dapr有控制平面服务。通过Dapr injector和Dapr Operator服务,跟用户应用程序部署在相同pod中的Dapr边车可以和集群中的Dapr组件进行连接和通知更新。​The ​​dapr-sentry​​​ service is a certificate authority that enables mutual TLS between Dapr sidecar instances for secure data encryption, as well as providing identity via ​​Spiffe​​​. For more information on the ​​Sentry​​​ service, read the ​​security overview​​dapr-sentry负责安全加密,详情查看​​security overview​​​Deploying and running a Dapr-enabled application into your Kubernetes cluster is as simple as adding a few annotations to the deployment schemes. Visit the ​​Dapr on Kubernetes docs​​在Kubernetes集群中部署和运行Dapr非常简单,只需要在deployment中添加一些配置项。详情访问​​​Dapr on Kubernetes docs​​。​

开发人员语言 SDK 和框架

Dapr offers a variety of SDKs and frameworks to make it easy to begin developing with Dapr in your preferred language.Dapr 提供了各种 SDK 和框架,使用 Dapr 开发您喜欢的语言变得很容易。

Dapr SDKs

To make using Dapr more natural for different languages, it also includes ​​language specific SDKs​​ for:为了使 Dapr 在不同语言中的使用更加自然,它还包括针对以下语言的 SDK:

C++ C + +Go 去吧Java 爪哇咖啡JavaScript.NETPHPPython 巨蟒Rust 生锈了

These SDKs expose the functionality of the Dapr building blocks through a typed language API, rather than calling the API. This enables you to write a combination of stateless and stateful functions and actors all in the language of your choice. And because these SDKs share the Dapr runtime, you get cross-language actor and function support.这些 SDK 通过类型化语言 API 公开 Dapr 构建块的功能,而不是调用 API。这使您能够用自己选择的语言编写无状态和有状态函数及参与者的组合。由于这些 SDK 共享 Dapr 运行时,因此您可以获得跨语言角色和函数支持。

开发者框架

Dapr can be used from any developer framework. Here are some that have been integrated with Dapr:Dapr 可以在任何开发者框架中使用:

Web

语言

框架

说明

​.NET​

​ASP.NET​

Brings stateful routing controllers that respond to pub/sub events from other services. Can also take advantage of ​​ASP.NET Core gRPC Services​

使用有状态路由控制器来响应来自其他服务的发布/订阅事件也可以利用​​ASP.NET Core gRPC Services​

​Java​

​Spring Boot​


集成和扩展

Visit the ​​integrations​​ page to learn about some of the first-class support Dapr has for various frameworks and external products, including:

访问​​integrations​​ 页面,了解 Dapr 对各种框架和外部产品的一流支持,包括:

Public cloud services 公共云端服务Visual Studio CodeGitHub

关于运维

Dapr is designed for ​​operations​​ and security. The Dapr sidecars, runtime, components, and configuration can all be managed and deployed easily and securely to match your organization’s needs.Dapr 关于运维和安全的设计使得Dapr 边车、运行时、组件和配置都可以轻松安全地进行管理和部署,以满足组织的需求。The ​​dashboard​​, installed via the Dapr CLI, provides a web-based UI enabling you to see information, view logs and more for running Dapr applications.通过 Dapr CLI 安装的仪表板提供了一个基于 Web 的 UI,使您能够查看信息、查看日志等,以便运行 Dapr 应用程序。The ​​monitoring tools support​​​ provides deeper visibility into the Dapr system services and side-cars and the ​​observability capabilities​​ of Dapr provide insights into your application such as tracing and metrics.监视工具支持提供了对 Dapr 系统服务和侧车更深入的可见性,Dapr 的可观察性能力提供了对应用程序的深入了解,比如跟踪和度量。

构建块解析

Dapr的构建块是模块化的,通过标准化HTTP和gRPC接口的访问。

A ​​building block​​ is an HTTP or gRPC API that can be called from your code and uses one or more Dapr components.Building blocks address common challenges in building resilient, microservices applications and codify best practices and patterns. Dapr consists of a set of building blocks, with extensibility to add new building blocks.The diagram below shows how building blocks expose a public API that is called from your code, using components to implement the building blocks’ capability.

一个构建块是可以通过HTTP或gRPC访问的一个或多个Dapr组件。Dapr由一组构建块组成,可以自定义添加构建块。

下图是Dapr提供的内置构建块

构建块

地址

描述

Service-to-service invocation

(服务间调用)

/v1.0/invoke

Service invocation enables applications to communicate with each other through well-known endpoints in the form of or gRPC messages. Dapr provides an endpoint that acts as a combination of a reverse proxy with built-in service discovery, while leveraging built-in distributed tracing and error handling.

Dapr提供了服务间调用的功能,通过该功能,服务间调用变得容易,用户应用程序不用再关心服务地址,只需要调用Dapr的接口并再接口中附带目标服务的约定名称即可访问。Dapr负责服务发现,同时可以进行分布式跟踪和异常处理。

State management

(状态管理)

/v1.0/state

Application state is anything an application wants to preserve beyond a single session. Dapr provides a key/value-based state and query APIs with pluggable state stores for persistence.

应用程序的状态是指在一个会话周期结束后,程序想要存储的数据等信息。Dapr提供键值对的形式的存储,并且可以持久化。


Publish and subscribe

(发布订阅)

/v1.0/publish 

/v1.0/subscribe

Pub/Sub is a loosely coupled messaging pattern where senders (or publishers) publish messages to a topic, to which subscribers subscribe. Dapr supports the pub/sub pattern between applications.

发布订阅模式是松耦合消息模式。发布者将消息发布到Dapr,订阅者从Dapr获得消息。


Resource bindings

(资源绑定)

/v1.0/bindings

A binding provides a bi-directional connection to an external cloud/on-premise service or system. Dapr allows you to invoke the external service through the Dapr binding API, and it allows your application to be triggered by events sent by the connected service.

资源绑定意味着dapr提供了程序对外使用服务的桥梁,通过dapr绑定提供的API,应用程序可以被外部触发也可以调用外部资源。

Actors

(参与者模式)

/v1.0/actors

An actor is an isolated, independent unit of compute and state with single-threaded execution. Dapr provides an actor implementation based on the virtual actor pattern which provides a single-threaded programming model and where actors are garbage collected when not in use.

Dapr参与者模块是一个计算和状态的独立单元,具有单线程特性,在不使用的时候自动回收。


Observability

(观察能力)

N/A

Dapr system components and runtime emit metrics, logs, and traces to debug, operate and monitor Dapr system services, components and user applications.

Observability组件提供系统监控能力。

Secrets

(密码管理)

/v1.0/secrets

Dapr provides a secrets building block API and integrates with secret stores such as public cloud stores, local stores and Kubernetes to store the secrets. Services can call the secrets API to retrieve secrets, for example to get a connection string to a database.

密钥管理

Configuration

(配置管理)

/v1.0-alpha1/configuration

Dapr provides a Configuration API that enables you to retrieve and subscribe to application configuration items for supported configuration stores. This enables an application to retrieve specific configuration information, for example, at start up or when configuration changes are made in the store.

配置管理

组件

Modular functionality used by building blocks and applications构建块使用了模块化功能

Dapr中的构建块是由模块化的组件构成的。

Dapr uses a modular design where functionality is delivered as a component. Each component has an interface definition. All of the components are pluggable so that you can swap out one component with the same interface for another. The ​​components contrib repository​​ is where you can contribute implementations for the component interfaces and extend Dapr’s capabilities.A building block can use any combination of components. For example the ​​actors​​​ building block and the ​​state management​​​ building block both use ​​state components​​​. As another example, the ​​pub/sub​​​ building block uses ​​pub/sub components​​.You can get a list of current components available in the hosting environment using the ​​dapr components​​ CLI command.Dapr使用模块化设计,其中功能作为组件交付。每个组件都有API接口定义。组件都是可插拔的,因此可以将具有相同接口的一个组件替换为另一个组件。组件库是您可以贡献组件接口的实现来扩展Dapr功能的地方。构建块可以使用组件的任意组合。例如,actors 和 state management 都使用了 state 组件。

Dapr的最小功能单元是组件,开源组件库中(go语言编写)提供了一些组件。这些组件构成了Dapr的构建块。组件可以任意组合成构建块。

actors构建块和state management都使用了state store组件。使用dapr components命令可以查看现有可用组件。

组件 (Component specification)

​Each component has a specification (or spec) that it conforms to. Components are configured at design-time with a YAML file which is stored in either a ​​components/local​​​ folder within your solution, or globally in the ​​.dapr​​​ folder created when invoking ​​dapr init​​​. These YAML files adhere to the generic ​​Dapr component schema​​, but each is specific to the component specification.​It is important to understand that the component spec values, particularly the spec ​​metadata​​​, can change between components of the same component type, for example between different state stores, and that some design-time spec values can be overridden at runtime when making requests to a component’s API. As a result, it is strongly recommended to review a ​​component’s specs​​​, paying particular attention to the sample payloads for requests to set the metadata used to interact with the component.​每个组件都有一个它所遵循的规范(或规范)。组件在设计时使用 YAML 文件进行配置,该文件存储在解决方案中的​​components/local​​文件夹中,或者全局存储在。调用 dapr init 时创建的 ​​.dapr​​ 文件夹。这些 YAML 文件遵循通用的 Dapr 组件方案,但是每个文件都特定于组件规范。重要的是要理解组件规格值,特别是规格元数据,可以在相同组件类型的组件之间变化,例如在不同的状态存储之间变化,并且当对组件的 API 发出请求时,一些设计时规格值可以在运行时被覆盖。因此,强烈建议检查组件的规范,特别注意用于设置用于与组件交互的元数据的请求的样例有效负载。

Dapr 组件方案



apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: [COMPONENT-NAME]
namespace: [COMPONENT-NAMESPACE]
spec:
type: [COMPONENT-TYPE]
version: v1
initTimeout: [TIMEOUT-DURATION]
ignoreErrors: [BOOLEAN]
metadata:
- name: [METADATA-NAME]
value: [METADATA-VALUE]

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:公关界007:当妈后你怀疑自己多少次?美赞臣的母亲节营销让我看到了妈妈的新生!
下一篇:使用 KubeSphere 和极狐GitLab 打造云原生持续交付系统
相关文章

 发表评论

暂时没有评论,来抢沙发吧~