5 changed files with 298 additions and 298 deletions
@ -1,171 +1,171 @@ |
|||
[Actors](../README.md) | Dapr.Actors 文档 |
|||
|
|||
# LINGYUN.Abp.Dapr.Client |
|||
|
|||
实现了Dapr文档中的服务间调用,项目设计与Volo.Abp.Http.Client一致,通过配置文件即可无缝替代Volo.Abp.Http.Client |
|||
|
|||
配置参考 [AbpRemoteServiceOptions](https://docs.abp.io/zh-Hans/abp/latest/API/Dynamic-CSharp-API-Clients#abpremoteserviceoptions) |
|||
|
|||
## 配置使用 |
|||
|
|||
模块按需引用 |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpDaprClientModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 注册代理类似于 Volo.Abp.Http.Client 模块 |
|||
context.Services.AddDaprClientProxies( |
|||
typeof(YouProjectInterfaceModule).Assembly, // 搜索 YouProjectInterfaceModule 模块下的远程服务定义 |
|||
RemoteServiceName |
|||
); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
|
|||
### 1、接口定义 |
|||
|
|||
```c# |
|||
|
|||
// IApplicationService 实现了 IRemoteService |
|||
public interface ISystemAppService : IApplicationService |
|||
{ |
|||
Task<string> GetAsync(); |
|||
} |
|||
|
|||
public class SystemInterfaceModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
|||
``` |
|||
|
|||
### 2、服务端 |
|||
|
|||
引用 Volo.Abp.AspNetCore.Mvc |
|||
|
|||
* 实现接口 |
|||
|
|||
```c# |
|||
|
|||
public class SystemAppService : ApplicationService, ISystemAppService |
|||
{ |
|||
public Task<string> GetAsync() |
|||
{ |
|||
retuen Task.FromResult("System"); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 创建模块 |
|||
|
|||
```c# |
|||
|
|||
[DependsOn( |
|||
typeof(SystemInterfaceModule), |
|||
typeof(AbpAspNetCoreMvcModule))] |
|||
public class SystemServerModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<IMvcBuilder>(mvcBuilder => |
|||
{ |
|||
mvcBuilder.AddApplicationPartIfNotExists(typeof(SystemServerModule).Assembly); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 发布到Dapr |
|||
|
|||
```shell |
|||
# --app-port .net程序映射端口 |
|||
# -H 对外暴露 http 监听端口 |
|||
# -G 对外暴露 grpc 监听端口 |
|||
dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run |
|||
|
|||
``` |
|||
|
|||
### 3、客户端 |
|||
|
|||
引用 LINGYUN.Abp.Dapr.Client |
|||
|
|||
* 配置文件 **appsettings.json** |
|||
|
|||
```json |
|||
|
|||
{ |
|||
"RemoteServices": { |
|||
"System": { |
|||
"AppId": "myapp", |
|||
"BaseUrl": "http://127.0.0.1:50000" |
|||
} |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 客户端代码 |
|||
|
|||
```c# |
|||
|
|||
// 模块依赖 |
|||
[DependsOn( |
|||
typeof(AbpDaprClientModule))] |
|||
public class SystemActorClientModule : AbpModule |
|||
{ |
|||
private const string RemoteServiceName = "System"; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 注册代理类似于 Volo.Abp.Http.Client 模块 |
|||
context.Services.AddDaprClientProxies( |
|||
typeof(SystemInterfaceModule).Assembly, // 搜索 SystemInterfaceModule 模块下的IRemoteService定义创建代理 |
|||
RemoteServiceName |
|||
); |
|||
} |
|||
} |
|||
|
|||
// 调用方法,直接依赖注入即可 |
|||
public class InvokeClass |
|||
{ |
|||
private readonly ISystemAppService _systemAppService; |
|||
|
|||
public InvokeClass(ISystemAppService systemAppService) |
|||
{ |
|||
_systemAppService = systemAppService; |
|||
} |
|||
|
|||
public async Task InvokeAsync() |
|||
{ |
|||
await _systemAppService.GetAsync(); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
|
|||
## 配置项说明 |
|||
|
|||
* AbpDaprRemoteServiceOptions.RemoteServices 配置Dapr.AppId |
|||
|
|||
```json |
|||
|
|||
{ |
|||
"RemoteServices": { |
|||
"System": { |
|||
"AppId": "myapp", |
|||
"BaserUrl": ""http://127.0.0.1:50000"" |
|||
} |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
|
|||
## 其他 |
|||
[Actors](../README.md) | Dapr.Client 文档 |
|||
|
|||
# LINGYUN.Abp.Dapr.Client |
|||
|
|||
实现了Dapr文档中的服务间调用,项目设计与Volo.Abp.Http.Client一致,通过配置文件即可无缝替代Volo.Abp.Http.Client |
|||
|
|||
配置参考 [AbpRemoteServiceOptions](https://docs.abp.io/zh-Hans/abp/latest/API/Dynamic-CSharp-API-Clients#abpremoteserviceoptions) |
|||
|
|||
## 配置使用 |
|||
|
|||
模块按需引用 |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpDaprClientModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 注册代理类似于 Volo.Abp.Http.Client 模块 |
|||
context.Services.AddDaprClientProxies( |
|||
typeof(YouProjectInterfaceModule).Assembly, // 搜索 YouProjectInterfaceModule 模块下的远程服务定义 |
|||
RemoteServiceName |
|||
); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
|
|||
### 1、接口定义 |
|||
|
|||
```c# |
|||
|
|||
// IApplicationService 实现了 IRemoteService |
|||
public interface ISystemAppService : IApplicationService |
|||
{ |
|||
Task<string> GetAsync(); |
|||
} |
|||
|
|||
public class SystemInterfaceModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
|||
``` |
|||
|
|||
### 2、服务端 |
|||
|
|||
引用 Volo.Abp.AspNetCore.Mvc |
|||
|
|||
* 实现接口 |
|||
|
|||
```c# |
|||
|
|||
public class SystemAppService : ApplicationService, ISystemAppService |
|||
{ |
|||
public Task<string> GetAsync() |
|||
{ |
|||
retuen Task.FromResult("System"); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 创建模块 |
|||
|
|||
```c# |
|||
|
|||
[DependsOn( |
|||
typeof(SystemInterfaceModule), |
|||
typeof(AbpAspNetCoreMvcModule))] |
|||
public class SystemServerModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<IMvcBuilder>(mvcBuilder => |
|||
{ |
|||
mvcBuilder.AddApplicationPartIfNotExists(typeof(SystemServerModule).Assembly); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 发布到Dapr |
|||
|
|||
```shell |
|||
# --app-port .net程序映射端口 |
|||
# -H 对外暴露 http 监听端口 |
|||
# -G 对外暴露 grpc 监听端口 |
|||
dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run |
|||
|
|||
``` |
|||
|
|||
### 3、客户端 |
|||
|
|||
引用 LINGYUN.Abp.Dapr.Client |
|||
|
|||
* 配置文件 **appsettings.json** |
|||
|
|||
```json |
|||
|
|||
{ |
|||
"RemoteServices": { |
|||
"System": { |
|||
"AppId": "myapp", |
|||
"BaseUrl": "http://127.0.0.1:50000" |
|||
} |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 客户端代码 |
|||
|
|||
```c# |
|||
|
|||
// 模块依赖 |
|||
[DependsOn( |
|||
typeof(AbpDaprClientModule))] |
|||
public class SystemActorClientModule : AbpModule |
|||
{ |
|||
private const string RemoteServiceName = "System"; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 注册代理类似于 Volo.Abp.Http.Client 模块 |
|||
context.Services.AddDaprClientProxies( |
|||
typeof(SystemInterfaceModule).Assembly, // 搜索 SystemInterfaceModule 模块下的IRemoteService定义创建代理 |
|||
RemoteServiceName |
|||
); |
|||
} |
|||
} |
|||
|
|||
// 调用方法,直接依赖注入即可 |
|||
public class InvokeClass |
|||
{ |
|||
private readonly ISystemAppService _systemAppService; |
|||
|
|||
public InvokeClass(ISystemAppService systemAppService) |
|||
{ |
|||
_systemAppService = systemAppService; |
|||
} |
|||
|
|||
public async Task InvokeAsync() |
|||
{ |
|||
await _systemAppService.GetAsync(); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
|
|||
## 配置项说明 |
|||
|
|||
* AbpDaprRemoteServiceOptions.RemoteServices 配置Dapr.AppId |
|||
|
|||
```json |
|||
|
|||
{ |
|||
"RemoteServices": { |
|||
"System": { |
|||
"AppId": "myapp", |
|||
"BaserUrl": "http://127.0.0.1:50000" |
|||
} |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
|
|||
## 其他 |
|||
|
|||
@ -1,124 +1,124 @@ |
|||
[Client](./LINGYUN.Abp.Dapr.Client/README.md) | Dapr.Client 文档 |
|||
|
|||
# Dapr.Actors 集成 |
|||
|
|||
## 配置使用 |
|||
|
|||
项目设计与 **Volo.Abp.Http.Client** 类似 |
|||
|
|||
### 1、接口定义 |
|||
|
|||
```c# |
|||
|
|||
// 定义在接口上的RemoteService.Name会被作为Actor的名称注册到Dapr |
|||
[RemoteService(Name = "System")] |
|||
public interface ISystemActor : IActor |
|||
{ |
|||
Task<string> GetAsync(); |
|||
} |
|||
|
|||
public class SystemActorInterfaceModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
|||
``` |
|||
|
|||
### 2、服务端 |
|||
|
|||
引用 LINGYUN.Abp.Dapr.Actors.AspNetCore |
|||
|
|||
* 实现接口 |
|||
|
|||
```c# |
|||
|
|||
public class SystemActor : Actor, ISystemActor |
|||
{ |
|||
public Task<string> GetAsync() |
|||
{ |
|||
retuen Task.FromResult("System"); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 创建模块 |
|||
|
|||
```c# |
|||
|
|||
// 模块会自动搜索实现了IActor的服务,注册为Dapr的Actors |
|||
[DependsOn( |
|||
typeof(AbpDaprActorsAspNetCoreModule))] |
|||
public class SystemActorServerModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
|||
``` |
|||
|
|||
* 发布到Dapr |
|||
|
|||
```shell |
|||
# --app-port .net程序映射端口 |
|||
# -H 对外暴露 http 监听端口 |
|||
# -G 对外暴露 grpc 监听端口 |
|||
dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run |
|||
|
|||
``` |
|||
|
|||
### 3、客户端 |
|||
|
|||
引用 LINGYUN.Abp.Dapr.Actors |
|||
|
|||
* 配置文件 **appsettings.json** |
|||
|
|||
```json |
|||
|
|||
{ |
|||
"RemoteServices": { |
|||
"Shop": { |
|||
"BaseUrl": "http://127.0.0.1:50000" |
|||
} |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 客户端代码 |
|||
|
|||
```c# |
|||
|
|||
// 模块依赖 |
|||
[DependsOn( |
|||
typeof(AbpDaprActorsModule))] |
|||
public class SystemActorClientModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 注册代理类似于 Volo.Abp.Http.Client 模块 |
|||
context.Services.AddDaprActorProxies( |
|||
typeof(SystemActorInterfaceModule).Assembly, // 搜索 SystemActorInterfaceModule 模块下的IActor定义 |
|||
"Shop" |
|||
); |
|||
} |
|||
} |
|||
|
|||
// 调用方法,直接依赖注入即可 |
|||
public class InvokeClass |
|||
{ |
|||
private readonly ISystemActor _systemActor; |
|||
|
|||
public InvokeClass(ISystemActor systemActor) |
|||
{ |
|||
_systemActor = systemActor; |
|||
} |
|||
|
|||
public async Task InvokeAsync() |
|||
{ |
|||
await _systemActor.GetAsync(); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
## 其他 |
|||
[Client](./LINGYUN.Abp.Dapr.Client/README.md) | Dapr.Actors 文档 |
|||
|
|||
# Dapr.Actors 集成 |
|||
|
|||
## 配置使用 |
|||
|
|||
项目设计与 **Volo.Abp.Http.Client** 类似 |
|||
|
|||
### 1、接口定义 |
|||
|
|||
```c# |
|||
|
|||
// 定义在接口上的RemoteService.Name会被作为Actor的名称注册到Dapr |
|||
[RemoteService(Name = "System")] |
|||
public interface ISystemActor : IActor |
|||
{ |
|||
Task<string> GetAsync(); |
|||
} |
|||
|
|||
public class SystemActorInterfaceModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
|||
``` |
|||
|
|||
### 2、服务端 |
|||
|
|||
引用 LINGYUN.Abp.Dapr.Actors.AspNetCore |
|||
|
|||
* 实现接口 |
|||
|
|||
```c# |
|||
|
|||
public class SystemActor : Actor, ISystemActor |
|||
{ |
|||
public Task<string> GetAsync() |
|||
{ |
|||
retuen Task.FromResult("System"); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 创建模块 |
|||
|
|||
```c# |
|||
|
|||
// 模块会自动搜索实现了IActor的服务,注册为Dapr的Actors |
|||
[DependsOn( |
|||
typeof(AbpDaprActorsAspNetCoreModule))] |
|||
public class SystemActorServerModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
|||
``` |
|||
|
|||
* 发布到Dapr |
|||
|
|||
```shell |
|||
# --app-port .net程序映射端口 |
|||
# -H 对外暴露 http 监听端口 |
|||
# -G 对外暴露 grpc 监听端口 |
|||
dapr run --app-id myapp --app-port 5000 -H 50000 -G 40001 -- dotnet run |
|||
|
|||
``` |
|||
|
|||
### 3、客户端 |
|||
|
|||
引用 LINGYUN.Abp.Dapr.Actors |
|||
|
|||
* 配置文件 **appsettings.json** |
|||
|
|||
```json |
|||
|
|||
{ |
|||
"RemoteServices": { |
|||
"Shop": { |
|||
"BaseUrl": "http://127.0.0.1:50000" |
|||
} |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
* 客户端代码 |
|||
|
|||
```c# |
|||
|
|||
// 模块依赖 |
|||
[DependsOn( |
|||
typeof(AbpDaprActorsModule))] |
|||
public class SystemActorClientModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 注册代理类似于 Volo.Abp.Http.Client 模块 |
|||
context.Services.AddDaprActorProxies( |
|||
typeof(SystemActorInterfaceModule).Assembly, // 搜索 SystemActorInterfaceModule 模块下的IActor定义 |
|||
"Shop" |
|||
); |
|||
} |
|||
} |
|||
|
|||
// 调用方法,直接依赖注入即可 |
|||
public class InvokeClass |
|||
{ |
|||
private readonly ISystemActor _systemActor; |
|||
|
|||
public InvokeClass(ISystemActor systemActor) |
|||
{ |
|||
_systemActor = systemActor; |
|||
} |
|||
|
|||
public async Task InvokeAsync() |
|||
{ |
|||
await _systemActor.GetAsync(); |
|||
} |
|||
} |
|||
|
|||
``` |
|||
|
|||
## 其他 |
|||
|
|||
Loading…
Reference in new issue