What is the best practices to listen/subscribe push notifications from RabbitMQ server?

Viewed 25

I have created 2 separated application using micro services architecture with NestJs. One is the main app (port 9000), other one is the Notification service (amqp & http port 9001).

I have successfully trigger notification from main app to the Notification service using RabbitMQ (amqp).

To listen to the notification, I have separated (port 3000) front-end application (ReactJs). What I've done are:

  1. From React, listen directly to RabbitMq using amqp-client. I was able to receive the push notification.
  2. From React, listen directly to RabbitMq using StompJs over WebSocket connection. I was able to receive the push notification.

The problem is, I don't think it's okay to listen directly to the RabbitMq server.

3rd solution that I was thinking is to add WebSocket in the Notification service, and then the Front-end app (ReactJs) will listen to Notification service instead of RabbitMq directly.

What is the best practices in this case? Which one do you think is the best, 1/2/3? Or do you have other advice?

Thank you.

1 Answers

I would never expose RabbitMQ to the front-end, as it is not meant to be open. RabbitMQ is perfectly designed for microservices, so multiple backend services can listen to any message. It is not meant to be open to the public, but only to be used in an internal network for server-to-server communication.

Besides that there are quite some security issues if you expose RabbitMQ to a front-end directly. It is a bad practice and you should always add a middleware, in your case the notification service, in between to listen to RabbitMQ and push a message back to the client again. You can use WebSockets for that.

Related