app.controller.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Controller, Get, OnModuleInit } from '@nestjs/common';
  2. import { AppService } from './app.service';
  3. // import { UtilsModule } from '@app/utils';
  4. import { grpcClientOptions } from './grpc-scene.options';
  5. import { ClientGrpc, Client } from '@nestjs/microservices';
  6. import { Observable } from 'rxjs';
  7. interface Point {
  8. x: string;
  9. y: string;
  10. z: string;
  11. }
  12. interface routeParam {
  13. sLocation: Point;
  14. eLocation: Point;
  15. sceneCode: string;
  16. }
  17. interface SceneGrpcService {
  18. getRoute(params: routeParam): Observable<any>;
  19. testMethod(data: { id: string; name: string }): Observable<any>;
  20. }
  21. @Controller()
  22. export class AppController implements OnModuleInit {
  23. @Client(grpcClientOptions) private readonly client: ClientGrpc;
  24. private sceneGrpcService: SceneGrpcService;
  25. constructor(private readonly appService: AppService) { }
  26. onModuleInit() {
  27. console.log('this.client', this.client);
  28. this.sceneGrpcService =
  29. this.client.getService<SceneGrpcService>('SceneGrpcService');
  30. }
  31. @Get()
  32. getHello(): string {
  33. // console.log('UtilsModule', UtilsModule);
  34. const params: routeParam = {
  35. sLocation: {
  36. x: '6.0',
  37. y: '0.0',
  38. z: '-4.0',
  39. },
  40. eLocation: {
  41. x: '4.0',
  42. y: '0.0',
  43. z: '-3.0',
  44. },
  45. sceneCode: 'Hello',
  46. };
  47. console.log('params', params);
  48. const test = this.sceneGrpcService.getRoute(params);
  49. test.subscribe((val) => {
  50. console.log('val', val);
  51. });
  52. return this.appService.getHello();
  53. }
  54. }