0
0
NestJSframework~10 mins

TCP 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 create a TCP client in NestJS.

NestJS
const client = ClientProxyFactory.create({ transport: [1] });
Drag options to blanks, or click blank then click option'
ATransport.GRPC
BTransport.HTTP
CTransport.REDIS
DTransport.TCP
Attempts:
3 left
💡 Hint
Common Mistakes
Using Transport.HTTP instead of Transport.TCP
Confusing Redis or gRPC transports with TCP
2fill in blank
medium

Complete 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'
A8080
B3001
C5000
D4000
Attempts:
3 left
💡 Hint
Common Mistakes
Using default port 8080 instead of 3001
Setting an invalid port number
3fill in blank
hard

Fix 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'
ATcpService
BClientProxy
CTransport
DMicroserviceOptions
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ClientProxy instead of Transport
Using a non-existent TcpService import
4fill in blank
hard

Fill 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'
Acreate
Blisten
Cconnect
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using connectMicroservice which returns the app instead of Microservice instance
5fill in blank
hard

Fill 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'
Alisten
Bsum
C{ a: 5, b: 3 }
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Calling listen() instead of connect()
Using wrong pattern name
Passing data as a string instead of an object