/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sample/03-microservices/src/math/math.controller.ts
21 строка
625 B
Kamil Myśliwiec
sample: revert microservices sample local updates
25 ноя 2024, 16:28
Не верифицирован
25 ноя 2024, 16:28
8ffae00
Код
Авторство
О чём код?
import { Controller, Get, Inject } from '@nestjs/common'; import { ClientProxy, MessagePattern } from '@nestjs/microservices'; import { Observable } from 'rxjs'; import { MATH_SERVICE } from './math.constants'; @Controller() export class MathController { constructor(@Inject(MATH_SERVICE) private readonly client: ClientProxy) {} @Get() execute(): Observable<number> { const pattern = { cmd: 'sum' }; const data = [1, 2, 3, 4, 5]; return this.client.send<number>(pattern, data); } @MessagePattern({ cmd: 'sum' }) sum(data: number[]): number { return (data || []).reduce((a, b) => a + b); } }