spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
708 stars 705 forks source link

Add support for request-based-sticky-session for RestTemplate-backed load-balancing #971

Open OlgaMaciaszek opened 3 years ago

OlgaMaciaszek commented 3 years ago

See https://stackoverflow.com/questions/68026243/request-based-sticky-session-configuration-with-spring-cloud-loadbalancer

jamesjallorina commented 1 week ago

Hi @OlgaMaciaszek,

I used the RestTemplate based on your answer from SO, and it's perfectly working. However, when I enable the servlet http session from the server side application in which the JSESSIONID will be added to the next succeeding client request header cookie the solution will not work. And the RestTemplate will default to round-robin load balancing. Do I need to have another alternative for http session such that only the cookie key with sc-lb-instance-id and cookie value with instance id will be sent?

Your help is very much appreciated!

Best regards,

James

OlgaMaciaszek commented 1 week ago

Hi @jamesjallorina, this issue has been added, but so far not assigned in the backlog. At this point, I'm not sure it will be included in backlog, but I will look into it and update here.

jamesjallorina commented 1 week ago

Hi @OlgaMaciaszek,

Thank you for the update!

I am new using spring framework, is it possible to provide me with some information on how long would it take for this to be available in the next release?

In the meantime, I am thinking of using the URL encoded JSESSIONID.

Best regards,

James

jamesjallorina commented 5 days ago

Hi @OlgaMaciaszek ,

Just an update!

I am able to make it work with URL-encoded JSESSIONID. The RestTemplate cookie management also needs to be disabled such that it will not re-send the same JSESSIONID cookie into the next new client request.

For example: return builder.requestFactory(SimpleClientHttpRequestFactory::new).build();