user11037262
user11037262

Reputation: 33

RabbitMQ in Springboot

I want to take advice. So I am creating a micro service which which will fetch data from the db and send back to the website whenever a customer opens the home page. So would using RabbitMQ be beneficial in such a case. I am thinking of adding the RabbitMQ layer between the Frontend and the Controllers in the spring boot microservice. So that none of the requests are missed. Would it help in reducing the latency as I want a very low latent system

Upvotes: 0

Views: 560

Answers (1)

Beri
Beri

Reputation: 11620

That would be a misuse of an message queues. Messages are used to delegate asynchronous actions, when you want something to be done (usually a long executing action), but You don't want to wait for the results. Or notify other services, that something has happened, but you are not sure if they are available or not.

Using MQ to fetch data into a webpage, would generate more problems that benefits. Web applications, do not provide push mechanisms (without crawling or web sockets). Web page can only call for data from Server, data cannot be pushed to the web page from server itself.

Proposed solution:

If you want to display data from a single datasource, or a single join can provide all data, then simple spring boot MVC will do.

If you are using multiple datasources (eg. tables), then you could use benefits of an SPA application. Return homepage with minimum layout. Then use multiple AJAX calls to fetch data from the database. This way user will call for all sources at the same time, and calls will not block each other.

If you want to go into microservices, you could write a node.js frontend app, that will fetch data from your spring-boot application, though REST api.

Your queues could be used to notify users about their task process, status change, etc, but for this you will have to use a web socket.

UPDATE (message async example):

User wants to generate a report - from all tables, and send it to a remote file storage (S3). From user perspactive it will be a simple button click. Because ation will be delegated to another service and executed asynchronously. User is only notified, that his action has been requested. Your service will publish a message that will request this report to be made (by another or same service), then pushed to data file storage.

After the process is completed (even after few hours), new message is published to user serviece or email, saying that report has been completed.

So User could click genrate report button, and go home. He will receive an email notification, when everything is completed.

Upvotes: 1

Related Questions