Spring Webflux会话管理 [英] Spring webflux session management

查看:681
本文介绍了Spring Webflux会话管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring boot 2,并在netty上运行spring webflux.

我想添加会话管理而不需要支持数据库或Redis服务器(因此Spring Session在这里似乎不是解决方案).

我可以在控制器中使用WebSession,但随后需要在负载均衡器上启用粘性会话,而我希望避免这种情况.

我想要的是以下之一:

  • 类似于Play框架的客户端会话(会话存储为cookie,并添加到每个后续请求中)
  • Hazelcast会话复制,但这仅适用于servlet容器

有人经历过同样的事情并找到了可行的解决方案吗?

解决方案

Spring Session计划提供ReactiveSessionRepository的Hazelcast实现.当前的计划是等待Hazelcast 4.0,它将以Java 8作为基准并使用CompletableFuture而不是他们自己的ICompletableFuture.您可以跟踪 gh-831 在此主题上的进展.

与此同时,您可以尝试使用ReactiveMapSessionRepository,并传入Hazelcast的IMap.

I am using Spring boot 2 with spring webflux running on netty.

I would like to add session management without needing to have a backing database or redis server (so Spring Session doesn't seem to be a solution here).

I could use WebSession in my controllers, but then I would need to enable sticky sessions on my load balancer, which I would prefer to avoid.

What I would like is one of the following:

  • Client side session like in Play framework (session is stored as a cookie and added onto each subsequent request)
  • Hazelcast session replication but this only works with servlet containers

Has anyone experienced the same thing and found a viable solution?

解决方案

Spring Session has plans for providing Hazelcast implementation of ReactiveSessionRepository. The current plan is to wait for Hazelcast 4.0, which will move to Java 8 as baseline and use CompletableFuture instead of their own ICompletableFuture. You can track gh-831 for progress on this topic.

In the meanwhile you could try and use ReactiveMapSessionRepository, passing in Hazelcast's IMap.

这篇关于Spring Webflux会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆