官术网_书友最值得收藏!

Verifying application functionality

After rebuilding and completing our application's startup, we should be able to access the mentioned web page in a browser at the following address: http://localhost:8080 (Spring Web MVC uses port 8080 for the web server as the default one. However, this can be changed in the application.properties file using the configuration line server.port=9090). After a few seconds, we may see the following output:

Connection opened
Temperature: 14.71 C
Temperature: 9.67 C
Temperature: 19.02 C
Connection closed
Connection opened
Temperature: 18.01 C
Temperature: 16.17 C

As we can see, our web page reactively receives events, preserving both client and server resources. It also supports autoreconnect in the case of network issues or timeouts. As the current solution is not exclusive to JavaScript, we may connect with other clients for example, curl. By running the next command in a terminal, we receive the following stream of raw, but not formatted, events:

> curl http://localhost:8080/temperature-stream
data:{"value":22.33210856124129}
data:{"value":13.83133638119636}
To explore more about Server-Sent Events technology and its integration with Spring Framework, read an excellent article by Ralph Schaer at  https://golb.hplar.ch/p/Server-Sent-Events-with-Spring.
主站蜘蛛池模板: 西充县| 泸州市| 禹城市| 西城区| 北辰区| 嵊泗县| 册亨县| 柳林县| 竹溪县| 许昌市| 衡东县| 长兴县| 英吉沙县| 长春市| 漳平市| 嘉善县| 英吉沙县| 沛县| 孝感市| 临颍县| 黄平县| 华坪县| 合肥市| 泽州县| 莱阳市| 吴忠市| 花莲市| 怀仁县| 塔城市| 孙吴县| 铜陵市| 商丘市| 永胜县| 南雄市| 平和县| 长乐市| 广河县| 旺苍县| 鲁山县| 襄汾县| 栾城县|