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