| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { Controller, Get, OnModuleInit } from '@nestjs/common';
- import { AppService } from './app.service';
- // import { UtilsModule } from '@app/utils';
- import { grpcClientOptions } from './grpc-scene.options';
- import { ClientGrpc, Client } from '@nestjs/microservices';
- import { Observable } from 'rxjs';
- interface Point {
- x: string;
- y: string;
- z: string;
- }
- interface routeParam {
- sLocation: Point;
- eLocation: Point;
- sceneCode: string;
- }
- interface SceneGrpcService {
- getRoute(params: routeParam): Observable<any>;
- testMethod(data: { id: string; name: string }): Observable<any>;
- }
- @Controller()
- export class AppController implements OnModuleInit {
- @Client(grpcClientOptions) private readonly client: ClientGrpc;
- private sceneGrpcService: SceneGrpcService;
- constructor(private readonly appService: AppService) { }
- onModuleInit() {
- console.log('this.client', this.client);
- this.sceneGrpcService =
- this.client.getService<SceneGrpcService>('SceneGrpcService');
- }
- @Get()
- getHello(): string {
- // console.log('UtilsModule', UtilsModule);
- const params: routeParam = {
- sLocation: {
- x: '6.0',
- y: '0.0',
- z: '-4.0',
- },
- eLocation: {
- x: '4.0',
- y: '0.0',
- z: '-3.0',
- },
- sceneCode: 'Hello',
- };
- console.log('params', params);
- const test = this.sceneGrpcService.getRoute(params);
- test.subscribe((val) => {
- console.log('val', val);
- });
- return this.appService.getHello();
- }
- }
|