On Sat, Jan 21, 2012 at 02:02:46AM +0000, [email protected] wrote:
> Hi all
>
> I am moving a session by replicating it from one app server to another app
> server when a certain scenario occurs.
>
> However, now I would like the haproxy to redirect the traffic to the new app
> server where the session resides.
> When the certain scenario occurs, I am setting a cookie TRANSITION=X. Where X
> is another node on which session has been replicated.
>
> As an example, in the flow below, session is assigned to node A at the end of
> first HTTP response. While processing second request on app server, I set the
> TRANSITION=X cookie.
>
> Is there a way by which haproxy can alter the node from A to node X in the
> JSESSIONID cookie?
Yes, you could have a dedicated backend which performs persistence based
on the TRANSITION cookie instead of JSESSIONID. Your frontend would then
use a rule based on the presence of the TRANSITION cookie to select the
second backend.
However you need to fix the JSESSIONID cookie in this second backend,
because the prefix will prevent your server from matching it.
So in short you should start from the following hints :
frontend XXX
use_backend bk_transition if { hdr_sub(cookie) TRANSITION= }
default backend bk_normal
backend bk_normal
...
backend bk_transition
# strip the server prefix from the JSESSIONID cookie
reqirep ^(Cookie:.*JSESSIONID=)[^~,;]*~(.*) \1\2
# cookie TRANSITION contains the server name
cookie TRANSITION
server s1 1.1.1.1:80 cookie X1
server s2 1.1.1.2:80 cookie X2
server s3 1.1.1.3:80 cookie X3
Regards,
Willy