0
votes

I have two servers configured in haproxy. and these servers are accessible by the url, http://example.api.com/testweb/service and based on this a round robin is performed.

and as of now my application is stateless. I want to enable state ful behavior based on the url patterns.

example :

http://example.api.com/testweb/service ( stateless )

http://example.api.com/testweb/cacheservice ( stateful/persisted/sticky enabled )

I think for the stateful/sticky url pattern, lb will respond with the custom cookie header and client will re-pass the same on the subsequent requests.

Can you please let me know what would be the configuration and how it is achieved ?

Thanks.

1

1 Answers

0
votes

haproxy supports cookie-based persistence. Take a look at the documentation for the cookie keyword.

For example, with the following config:

cookie  my_balancing_cookie insert indirect nocache
server  app1 127.0.0.1:5001 cookie use_app1 check
server  app2 127.0.0.1:5002 cookie use_app2 check
server  app3 127.0.0.1:5003 cookie use_app3 check

The cookie my_balancing_cookie will be set if it doesn't exist (in this case, the default balancing strategy is used). If it does exist and has a value like "use_app3", traffic will go to app3.