monorepo-microservice-rbac/apps/services
2023-10-10 21:18:20 +08:00
..
alg feat: python发布消息到nats-server 2023-09-14 14:05:21 +08:00
aorta fear: nats log promihous 2023-10-10 21:18:20 +08:00
cert fear: nats log promihous 2023-10-10 21:18:20 +08:00
dicom fear: nats log promihous 2023-10-10 21:18:20 +08:00
dmp fear: nats log promihous 2023-10-10 21:18:20 +08:00
logger fear: nats log promihous 2023-10-10 21:18:20 +08:00
readme.md feat: remove emit cmd 2023-10-10 16:48:34 +08:00

发布订阅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);
}