forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.controller.ts
More file actions
25 lines (21 loc) · 985 Bytes
/
Copy pathclient.controller.ts
File metadata and controls
25 lines (21 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Controller } from '../../../src/common/utils/decorators/controller.decorator';
import { Client } from '../../../src/microservices/utils/client.decorator';
import { RequestMapping } from '../../../src/common/utils/decorators/request-mapping.decorator';
import { ClientProxy } from '../../../src/microservices/client/client-proxy';
import { Observable } from 'rxjs';
import { Transport } from '../../../src/common/enums/transport.enum';
import 'rxjs/add/operator/catch';
const MicroserviceClient = { transport: Transport.TCP, port: 5667 };
@Controller()
export class ClientController {
@Client(MicroserviceClient)
public client: ClientProxy;
@RequestMapping({ path: 'client' })
public sendMessage(req, res) {
const pattern = { command: 'add' };
const data = [ 1, 2, 3, 4, 5 ];
this.client.send(pattern, data)
.catch((err) => Observable.empty())
.subscribe((result) => res.status(200).json({ result }));
}
}