DEV Community

Discussion on: Build an API Gateway with NestJs in 10 minutes

Collapse
 
iamgokul profile image
Gokulnath

I have a scenario where I want a microservice to listen to HTTP Requests and also to the events emitted from the other service. How can I do that ?

Collapse
 
danmt profile image
Daniel Marin

You need a socket listening on a port and use the socket.on(event) to call the same method your controller is calling.

You can also use a message queue as entry point and make sure both your http calls and socket events dispatch a message, then you consume from your queue and execute the method. This approach is better in terms of scalability, you could later add a new endpoint in a different service and it will trigger the same behavior.