Challenge - 5 Problems
TCP Transport Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Understanding TCP Transport Client Behavior in NestJS
Consider a NestJS microservice client configured with TCP transport connecting to a server. What will happen if the server is not running when the client tries to send a message?
NestJS
const client = ClientProxyFactory.create({ transport: Transport.TCP, options: { host: '127.0.0.1', port: 3001 } });
async function sendMessage() {
return client.send('test_pattern', { data: 'hello' }).toPromise();
}
sendMessage().catch(err => console.error(err));Attempts:
2 left
💡 Hint
Think about how NestJS TCP clients handle connection retries by default.
✗ Incorrect
By default, NestJS TCP clients will attempt to reconnect and retry sending messages if the server is not available. This means the message is queued and retried until the server responds or the client times out.
📝 Syntax
intermediate2:00remaining
Correct TCP Transport Server Setup in NestJS
Which of the following code snippets correctly creates a TCP microservice server in NestJS listening on port 4000?
Attempts:
2 left
💡 Hint
Check how the port is specified inside the options object.
✗ Incorrect
The correct way to configure a TCP microservice server in NestJS is to specify the transport as Transport.TCP and provide the port inside the options object.
🔧 Debug
advanced2:00remaining
Diagnosing TCP Transport Connection Refused Error
A NestJS TCP client throws a "connect ECONNREFUSED" error when trying to send a message. Which of the following is the most likely cause?
Attempts:
2 left
💡 Hint
ECONNREFUSED means the connection was actively refused by the target machine.
✗ Incorrect
"ECONNREFUSED" indicates that the client tried to connect but no server was listening on the target port, so the connection was refused.
❓ state_output
advanced2:00remaining
Output of TCP Client Send with Timeout
Given a NestJS TCP client configured with a 2-second timeout, what will be the output if the server takes 5 seconds to respond?
NestJS
const client = ClientProxyFactory.create({
transport: Transport.TCP,
options: { host: '127.0.0.1', port: 3001, timeout: 2000 }
});
async function send() {
try {
const response = await client.send('delayed_response', {}).toPromise();
console.log('Response:', response);
} catch (err) {
console.log('Error:', err.message);
}
}
send();Attempts:
2 left
💡 Hint
Consider the effect of the timeout option on client requests.
✗ Incorrect
The timeout option causes the client to throw a timeout error if the server does not respond within the specified time.
🧠 Conceptual
expert3:00remaining
TCP Transport Message Pattern Matching in NestJS
In a NestJS TCP microservice, how does the server determine which handler to invoke for an incoming message?
Attempts:
2 left
💡 Hint
Think about how NestJS uses decorators to route messages.
✗ Incorrect
The server uses the pattern string sent by the client to find the matching @MessagePattern handler method.