Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a TCP client in NestJS.
NestJS
const client = ClientProxyFactory.create({ transport: [1] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Transport.HTTP instead of Transport.TCP
Confusing Redis or gRPC transports with TCP
✗ Incorrect
Transport.TCP is used to specify TCP transport in NestJS microservices.
2fill in blank
mediumComplete the code to set the TCP port to 3001.
NestJS
const microserviceOptions = { transport: Transport.TCP, options: { port: [1] } }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using default port 8080 instead of 3001
Setting an invalid port number
✗ Incorrect
Port 3001 is set here to specify where the TCP microservice listens.
3fill in blank
hardFix the error in the TCP microservice creation by completing the missing import.
NestJS
import { [1] } from '@nestjs/microservices';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ClientProxy instead of Transport
Using a non-existent TcpService import
✗ Incorrect
Transport must be imported from '@nestjs/microservices' to configure TCP transport.
4fill in blank
hardFill in the blank to create a TCP microservice on port 4000.
NestJS
const microservice = app.[1]Microservice({ transport: Transport.TCP, options: { port: 4000 } });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using connectMicroservice which returns the app instead of Microservice instance
✗ Incorrect
Use createMicroservice to create the microservice instance.
5fill in blank
hardFill all three blanks to send a message with pattern 'sum' and data {a: 5, b: 3} using the TCP client.
NestJS
const client = ClientProxyFactory.create({ transport: Transport.TCP });
await client.[1]();
const result = await client.send({ cmd: '[2]' }, [3]).toPromise(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling listen() instead of connect()
Using wrong pattern name
Passing data as a string instead of an object
✗ Incorrect
First, connect the client with connect(), then send a message with pattern 'sum' and data object.