这是基于vue-vben-admin 模板适用于abp Vnext的前端管理项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
feijie 984310f316 feat(docs): 添加Dapr模块文档 1 year ago
..
LINGYUN/Abp/Dapr/Actors upgrade abp framework to 8.2.0 1 year ago
Microsoft/Extensions/DependencyInjection upgrade abp framework to 8.2.0 1 year ago
FodyWeavers.xml upgrade(abp): upgrade abp framework to 7.4.0 2 years ago
FodyWeavers.xsd upgrade(abp): upgrade abp framework to 7.4.0 2 years ago
LINGYUN.Abp.Dapr.Actors.csproj upgrade abp framework to 8.2.0 1 year ago
README.EN.md feat(docs): 添加Dapr模块文档 1 year ago
README.md feat(docs): 添加Dapr模块文档 1 year ago

README.md

LINGYUN.Abp.Dapr.Actors

Dapr.IActor客户端代理模块

功能特性

  • Dapr Actors的动态代理生成
  • 与ABP远程服务系统集成
  • 支持Actor认证和授权
  • 多租户支持
  • 自动请求/响应处理
  • 自定义错误处理
  • 文化和语言标头支持

配置使用

模块按需引用

[DependsOn(typeof(AbpDaprActorsModule))]
public class YouProjectModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        // 注册代理类似于 Volo.Abp.Http.Client 模块
        context.Services.AddDaprActorProxies(
            typeof(YouProjectActorInterfaceModule).Assembly, // 搜索 YouProjectActorInterfaceModule 模块下的IActor定义
            RemoteServiceName
        );
    }
}

配置选项

{
    "RemoteServices": {
        "Default": {
            "BaseUrl": "http://localhost:3500",  // 必需,Dapr HTTP端点
            "DaprApiToken": "your-api-token",    // 可选,Dapr API Token
            "RequestTimeout": "30000"            // 可选,请求超时时间(毫秒,默认:30000
        }
    }
}

实现示例

  1. Actor接口定义
public interface ICounterActor : IActor
{
    Task<int> GetCountAsync();
    Task IncrementCountAsync();
}
  1. Actor实现
public class CounterActor : Actor, ICounterActor
{
    private const string CountStateName = "count";

    public CounterActor(ActorHost host) : base(host)
    {
    }

    public async Task<int> GetCountAsync()
    {
        var count = await StateManager.TryGetStateAsync<int>(CountStateName);
        return count.HasValue ? count.Value : 0;
    }

    public async Task IncrementCountAsync()
    {
        var currentCount = await GetCountAsync();
        await StateManager.SetStateAsync(CountStateName, currentCount + 1);
    }
}
  1. 客户端使用
public class CounterService
{
    private readonly ICounterActor _counterActor;

    public CounterService(ICounterActor counterActor)
    {
        _counterActor = counterActor;
    }

    public async Task<int> GetAndIncrementCountAsync()
    {
        var count = await _counterActor.GetCountAsync();
        await _counterActor.IncrementCountAsync();
        return count;
    }
}

注意事项

  • Actor方法必须返回TaskTask<T>
  • Actor方法最多只能有一个参数
  • Actor实例是单线程的,一次只能处理一个请求
  • Actor状态由Dapr运行时管理
  • 模块自动处理:
    • 认证标头
    • 租户上下文
    • 文化信息
    • 请求超时
    • 错误处理

错误处理

模块为Actor调用提供自定义错误处理:

  • AbpDaprActorCallException:当Actor方法调用失败时抛出
  • ActorMethodInvocationException:包含有关失败的详细信息
  • 错误响应包括:
    • 错误消息
    • 错误代码
    • 原始异常类型

查看更多