DEV Community

Discussion on: Building authentication for microservices using NestJS

Collapse
 
shubh151994 profile image
shubh151994

Hi Firstly thank you for this its really helpful

I just have few doubt , auth is running at 3000 and user is running at 3010 then what is happening on port 4000 and 4010 .

Collapse
 
alesanchez profile image
Ale Sánchez • Edited

Hi! Thank you for reading. The difference is just that the "message" interface is listening on TCP port 4000 and 4010 and the standard HTTP interface is listening on port 3000 and 3010.

If you configure a ClientProxy with transport TCP and port 3000, those messages are not going to arrive to the auth microservice, since it is waiting for messages on port 4000.

Being that said, you can use the same port for por listening HTTP requests and messages, so you could configure a microservice as:

/* THIS WON'T WORK
app.connectMicroservice({
transport: Transport.TCP,
  options: {
    host: 'localhost',
    port: 3010
  }
});

app.startAllMicroservicesAsync();
await app.listen(3010);
DON'T TRY THIS */
Enter fullscreen mode Exit fullscreen mode

Let me know if you have any more doubts :)

Collapse
 
nigeltran profile image
nigeltran

Hi,

Thanks for the article, it is very helpful. I just wonder if you can use same port for app and service like the example above? I tried that settings, but got error that port 3000 is already taken. Do you know how to config it to the same port?

Thanks!

Thread Thread
 
alesanchez profile image
Ale Sánchez

Oops... I made a mistake there, you cannot configure both things in the same port because, as you said, it's going to throw an error because the port has been already taken. I edited the comment. Sorry.