简体   繁体   中英

How can React show data as soon as backend gets data from MQ

I am using Spring Boot as backend.

And I use @JmsListener to listen specific ActiveMQ.

My purpose is as soon as listener gets data from MQ, backend will send this data to frontend(I use React) immediately, and shows data in GUI.

How can I achieve this requirement?

You can take advantage of websockets in order to make a real time communication between backend and frontend, so that the backend can send the produced information to the client (React App). Take a look in the article here to find an example of such case.

Alernative

The most common solution without websockets because of the added complexity would be that the React Frontend makes regular pings to backend for example with interval of 4-5 seconds until the backend is able to respond. While pinging the backend you can have the user wait with a spinner or such notification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM