Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky Sessions and Zuul in Spring Cloud

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.

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

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

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

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.

like image 997
EvilJinious1 Avatar asked Mar 23 '15 18:03

EvilJinious1


People also ask

Is Zuul supported by spring cloud?

Zuul is built on servlet 2.5 (works with 3. x), using blocking APIs. It doesn't support any long lived connections, like websockets. Gateway is built on Spring Framework 5, Project Reactor and Spring Boot 2 using non-blocking APIs.

What is the use of Zuul in spring cloud?

Zuul server is an application server that handles routing in a microservices architecture in Spring Boot applications. Zuul handles the dynamic routing of requests to specific microservices.

What is the difference between Zuul and Eureka?

Eureka belongs to "Open Source Service Discovery" category of the tech stack, while Zuul can be primarily classified under "Microservices Tools". Eureka is an open source tool with 8.16K GitHub stars and 2.27K GitHub forks.

Can Zuul work without Eureka?

GitHub - rishabhverma17/microservice-zuul-without-eureka: This service can be used to create microservice architecture with Gateway/Reverse Proxy using Zuul without using Eureka. This service can be used to create microservice architecture with Gateway/Reverse Proxy using Zuul without using Eureka.


1 Answers

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.

like image 95
Dave Syer Avatar answered Oct 17 '22 23:10

Dave Syer