- Hands-On Reactive Programming in Spring 5
- Oleh Dokuka Igor Lozynskyi
- 312字
- 2021-07-23 16:36:19
Building applications with @EventListener
To play with the Publish-Subscribe pattern in Spring Framework, let's do an exercise. In turn, assume that we have to implement a simple web service that shows the current temperature in the room. For this purpose, we have a temperature sensor, which sends events with the current temperature in Celsius from time to time. We potentially want to have both mobile and web applications, but for the sake of conciseness, we are implementing only a simple web application. Furthermore, as questions of communication with microcontrollers are out of the scope of this book, we are simulating a temperature sensor using a random number generator.
To make our application following the reactive design, we cannot use an old pulling model for data retrieval. Fortunately, nowadays we have some well-adopted protocols for asynchronous message propagation from a server to a client, namely WebSockets and Server-Sent Events (SSE). In the current example, we will use the last one. The SSE allows a client to receive automatic updates from a server, and is commonly used to send message updates or continuous data streams to a browser. With the inception of HTML5, all modern browsers have a JavaScript API called EventSource, which is used by clients who request a particular URL to receive an event stream. The EventSource also autoreconnects by default in the case of communication issues. It is important to highlight that SSE is an excellent candidate for fulfilling communication needs between components in the reactive system. On par with WebSocket, SSE is used a lot in this book.
High Performance Browser Networkingby Ilya Grigorik at https://hpbn.co/server-sent-events-sse/.
Also, the following article by Mark Brown gives a good comparison between WebSockets and Server-Sent Events:
https://www.sitepoint.com/real-time-apps-websockets-server-sent-events/
- Mastering Machine Learning for Penetration Testing
- 智能網聯汽車V2X與智能網聯設施I2X
- 工業控制網絡安全技術與實踐
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- NB-IoT物聯網技術解析與案例詳解
- Practical Web Design
- Building RESTful Web services with Go
- 物聯網之霧:基于霧計算的智能硬件快速反應與安全控制
- CCNP TSHOOT(642-832)認證考試指南
- 5G技術與標準
- 工業互聯網創新實踐
- 物聯網場景設計與開發(初級)
- 紅藍攻防:構建實戰化網絡安全防御體系
- 局域網組成實踐
- 沖擊:5G如何改變世界