Dapr - actors之构建块(5)
State persistence
状态持久性
Actor state is persisted using the Dapr state management building block. Because actors can execute multiple state operations in a single turn, the state store component must support multi-item transactions. At the time of writing, the following state stores support multi-item transactions:
使用 Dapr 状态管理构建块保存Actor 状态。 由于执行组件可以一轮执行多个状态操作,因此状态存储组件必须支持多项事务。 撰写本文时,以下状态存储支持多项事务:
- Azure Cosmos DB
- MongoDB
- MySQL
- PostgreSQL
- Redis
- RethinkDB
- SQL Server
To configure a state store component for use with actors, you need to append the following metadata to the state store configuration:
若要配置要与Actors 一起使用的状态存储组件,需要将以下元数据附加到状态存储配置:
YAML
- name: actorStateStore
value: "true"
Here's a complete example for a Redis state store:
下面是 Redis 状态存储的完整示例:
YAML
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
- name: actorStateStore
value: "true"
Use the Dapr .NET SDK
使用 Dapr .NET SDK
You can create an actor model implementation using only HTTP/gRPC calls. However, it's much more convenient to use the language specific Dapr SDKs. At the time of writing, the .NET, Java and Python SDKs all provide extensive support for working with actors.
你只能使用 HTTP/gRPC 调用来创建Actor 模型实现。 但是,更方便的方法是使用特定于语言的 Dapr Sdk。 撰写本文时,.NET、Java 和 Python Sdk 都为使用Actor 提供了广泛的支持。
To get started with the .NET Dapr actors SDK, you add a package reference to Dapr.Actors
to your service project. The first step of creating an actual actor is to define an interface that derives from . Clients use the interface to invoke operations on the actor. Here's a simple example of an actor interface for keeping scores:IActor
若要开始使用 .NET Dapr actors SDK,你可以将包引用Dapr.Actors
添加到 你的服务项目。 创建实际Actor 的第一步是定义并继承的接口 IActor
。 客户端使用接口调用Actor 上的操作。 下面是一个简单的Actor 接口示例,用于保持分数:
C#
public interface IScoreActor : IActor
{
Task<int> IncrementScoreAsync();
Task<int> GetScoreAsync();
}
- 点赞
- 收藏
- 关注作者
评论(0)