A simple example of using Redis PubSub and Spring Reactive Server Side Events for real-time push events to the browser

Spring Boot v2.0.3.RELEASE

Coding using reactive functional style (as opposed to annotation-based)

Spring Initializr Dependencies: “Reactive Web”

Redis Driver Used: Jedis

Language: Kotlin

Scenario and design choices

The scenario described in this article is depicted below:


Reactive Spring: Combining Server-Side Events with Redis PubSub for real-time pu ...
The endgame is to have events published by some 3rd party process to a Redis PubSub channel . Spring is configured to subscribe to this channel, and convert any received events to HTTP Server-sent Events [SSE] which are subsequently sent to the client browser.

Even for such a simple scenario, some planning is required. There are (almost too many) options on how to go about this. For example, you could use Spring Data Redis to interface with redis, rather than directly using the jedis library as I did. You could also go full blown reactive and use the lettuce redis driver instead, which supports reactive programming. See which works best for you, and most importantly which is easier to maintain and understand.

Initial setup

As always, the Spring Framework makes it a breeze to get a functioning reactive webstack up and running.

DefaultRouter.ktdefines a single route (GET /sse) which is handled by the sseEvents method defined in homeHandler.kt .

本文数据库(综合)相关术语:系统安全软件

主题: SpringRedisReactKotlinSSE
tags: Spring,Redis,reactive,events,Server,Events,using,Reactive
分页:12
转载请注明
本文标题:Reactive Spring: Combining Server-Side Events with Redis PubSub for real-time pu ...
本站链接:https://www.codesec.net/view/578920.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(119)