monorepo-microservice-rbac/apps/services/readme.md
2023-08-27 14:37:59 +08:00

21 lines
500 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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