Dapr - actors之构建块(5)

举报
小云悠悠zZ 发表于 2023/01/30 16:34:38 2023/01/30
【摘要】 若要开始使用 .NET Dapr actors SDK,你可以将包引用Dapr.Actors 添加到 你的服务项目。 创建实际Actor 的第一步是定义并继承的接口 IActor 。 客户端使用接口调用Actor 上的操作。
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();
}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。