Reputation: 613
I am working on an application which receives messages from the counterpart. what I want is display these messages to UI. I am using spring boot 2 & this is a web application.
what I am planning is to add messages to list and then send those messages to UI.
now the issue is I can use an observable list or can use my own implementation of the list to store messages but I am confused about how I am going to send these messages from the list to UI (web browser) so that messages will be displayed on UI.
I am using JSP for a view(UI).
Please suggest me about this.
Upvotes: 0
Views: 1838
Reputation: 1369
The very nature of your problem can be modeled as a stream. So, I would recommend getting started using the WebFlux libraries and use reactive streams. And in your controller, set your outgoing content type to Streaming JSON and the data that you are sending, wrap it into a Mono
or Flux
(or their RxJava counterpart if you are using RxJava and not Project Reactor), this would be a nice solution to what you are trying to achieve.
You can also use WebSocket protocol but the only issue with that would be that your TCP connection will remain open and as such, it's a potential issue on mobile devices.
Upvotes: 1
Reputation: 431
What you may need is Web socket protocol. You can read about implementing a web socket in Spring boot here:
https://spring.io/guides/gs/messaging-stomp-websocket/
More about web socket: - https://www.maxcdn.com/one/visual-glossary/websocket/
Other alternative will be using HTTP streaming.
https://medium.com/swlh/streaming-data-with-spring-boot-restful-web-service-87522511c071
Upvotes: 0