即时贴和Spring Cloud中的Zuul [英] Sticky Sessions and Zuul in Spring Cloud

查看:74
本文介绍了即时贴和Spring Cloud中的Zuul的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组微服务,我们使用zuul从前端进行路由,这是一种使用Spring Cloud将uri上下文路径映射到特定微服务的方式.

I have a set of micro services and we use zuul for routing from the front end as a way of mapping a uri context path to a specific micro service using spring cloud.

在内部和外部,我们都使用spring OAuth2,并且效果很好.

Internally and externally we use spring OAuth2 and that works quite well.

但是,对于一种特定的服务,已经出现了对SAML的要求,这对该服务提出了粘性会话要求.

However, for one specific service there has arisen a requirement for SAML and this imposes a sticky sessions requirement for that service.

还有人考虑过这一点,以及为zuul提供粘性会话支持的正确方法是什么.

Has another considered this and what would eb the correct way to put in sticky session support for zuul.

作为一种变通办法,直到我弄清楚了,我将一些来自HAProxy的请求直接路由到该服务,该请求来自我们前端的HAProxy.

As a work around until I figure this out, I am routing some requests form the HAProxy that we have on the front end directly to this service.

推荐答案

我假设如果您需要粘性会话,则需要多个后端,因此必须使用功能区过滤器.即时贴会话可以添加为IRule,例如

I assume if you need sticky sessions that you have multiple backends, so you must be using the Ribbon filter. Sticky sessions could be added as an IRule, e.g.

@RibbonClient(value="myui", configuration=UiRibbonConfiguration.class)
public class UiRibbonConfiguration {
  @Bean
  public IRule loadBalancerRule() {
    return new MyStickySessionRule();
  }
}

加上一个ZuulFilter(或后端中的servlet Filter),该cookie添加了用于关联的cookie-每个后端实例必须唯一地标识自己,然后在MyStickySessionRule中,您必须查看传入的cookie决定将请求发送到哪个实例(例如,如果后端是Spring Boot应用,则可以将"X-Application-Context"标头值作为cookie发送).

plus a ZuulFilter (or a servlet Filter in your backend) that adds a cookie for correlation - each backend instance has to uniquely identify itself, and then in the MyStickySessionRule you have to look at the incoming cookie to decide which instance to send the request to (e.g. you could send the "X-Application-Context" header value as a cookie if the backend is a Spring Boot app).

如果您可以在后端使用Spring Session,则不需要粘性会话.

N.B. if you can use Spring Session in the backend you won't need sticky sessions.

这篇关于即时贴和Spring Cloud中的Zuul的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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