Sticky Sessions and Zuul in Spring Cloud

前端 未结 1 536
遥遥无期
遥遥无期 2021-02-04 19:45

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.

Inte

相关标签:
1条回答
  • 2021-02-04 20:27

    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();
      }
    }
    

    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).

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

    0 讨论(0)
提交回复
热议问题