monorepo-microservice-rbac/apps/services/readme.md

21 lines
482 B
Markdown
Raw Normal View History

2023-08-27 14:37:59 +08:00
# 发布订阅EventPattern
> @MessagePattern: 基于rpc比较喜欢用一个菠萝一个坑
```ts
// 网关
@Get('/hello')
async getHello(): Promise<any> {
2023-10-10 16:48:34 +08:00
const pattern = 'sum';
2023-08-27 14:37:59 +08:00
const payload = [1, 2];
// this.client.emit(pattern,payload)没有返回值
const it = await this.client.send<number[]>(pattern, payload);
return `收到返回值: ${it}`;
}
// 服务
2023-10-10 16:48:34 +08:00
@EventPattern('sum')
2023-08-27 14:37:59 +08:00
sum(data: number[]): number {
return (data || []).reduce((a, b) => a + b);
}
```