0
0
NestJSframework~10 mins

gRPC transport in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the gRPC transport from NestJS microservices.

NestJS
import { [1] } from '@nestjs/microservices';
Drag options to blanks, or click blank then click option'
AGrpcTransport
BGrpcClient
CGrpcService
DGrpcOptions
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing GrpcTransport with GrpcOptions.
Using GrpcService which does not exist.
Importing GrpcClient instead of GrpcOptions.
2fill in blank
medium

Complete the code to set the transport type to gRPC in the microservice options.

NestJS
const grpcOptions = {
  transport: [1],
  options: {
    package: 'hero',
    protoPath: 'hero.proto'
  }
};
Drag options to blanks, or click blank then click option'
ATransport.REDIS
BTransport.GRPC
CTransport.TCP
DTransport.HTTP
Attempts:
3 left
💡 Hint
Common Mistakes
Using Transport.HTTP instead of Transport.GRPC.
Setting transport to Transport.TCP or Transport.REDIS by mistake.
3fill in blank
hard

Fix the error in the code to correctly create a gRPC microservice.

NestJS
const app = await NestFactory.createMicroservice(AppModule, {
  transport: Transport.GRPC,
  options: {
    package: 'hero',
    protoPath: [1]
  }
});
Drag options to blanks, or click blank then click option'
A'./proto/hero.proto'
B'hero.proto'
C'./hero.proto'
D'proto/hero.proto'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting './' causes the file not to be found.
Using incorrect folder paths that don't match the project structure.
4fill in blank
hard

Fill both blanks to define a gRPC service client in a NestJS module.

NestJS
imports: [
  ClientsModule.register([
    {
      name: '[1]',
      transport: Transport.GRPC,
      options: {
        package: '[2]',
        protoPath: './hero.proto'
      }
    }
  ])
]
Drag options to blanks, or click blank then click option'
AHERO_PACKAGE
Bhero
CHERO_SERVICE
DHeroService
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up client name and package name.
Using incorrect package names that don't match proto.
5fill in blank
hard

Fill all three blanks to implement a gRPC method handler in a NestJS controller.

NestJS
@Controller()
export class HeroController {
  @GrpcMethod('[1]', '[2]')
  findOne(data: { id: number }, metadata: any): [3] {
    return { id: data.id, name: 'HeroName' };
  }
}
Drag options to blanks, or click blank then click option'
AHeroService
BFindOne
C{ id: number; name: string }
DHero
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect service or method names in the decorator.
Returning wrong types that don't match proto messages.