Options

aflex for post data load balancing and persistence

Posted by jmaddox

Do we have a generic aflex somewhere that does the following?

Look inside a POST for user=xxxxxxx, and load balance/persist based on name=value?

Comments

  • Options
    edited February 2014
    Posted by ddesmidt

    aFleX can look at client and server response and make specific actions based on that.
    Here is an aFleX example below that replies to your question.
    The aFlex rule:
    . Collects the POST data
    . Collect the username displayed after "user=".
    Note: In the aFleX the username in the POST is after "user=" and up to "," or the end of the POST. You may need to modify the aFleX to your specific case.
    . Looks at the persist table to know to what server to forward that user request to
    Note: If that's a new user, then load balance it to any available server.
    . Creates an entry in the persist table for 300 seconds


    Important Note:
    This aFleX selects the right server for POST requests and not other requests.
    So use cookie persistence with option "Insert Always" on your VIP to be sure that user will stay on the same server also for the other requests.

    Code:

    when HTTP_REQUEST { # Collect client's request data if that's a POST if {[HTTP::method] eq "POST"} { HTTP::collect log "Collect POST data..." } } when HTTP_REQUEST_DATA { # Find username set username [findstr [HTTP::payload] "user=" 5 ","] if {$username eq ""} { log "No username found!!!" } else { log "User = \"$username\"" # Check if user logged in in the last 300 secs set p [persist lookup uie $username all] if { $p ne "" } { # User logged in the last 300 secs log "User = \"$username\" found user in persistency-table ([lindex $p 0] [lindex $p 1])" } else { # User didn't log in the last 300 secs log "User = \"$username\" not found in persistency-table" } } } when HTTP_RESPONSE { # Create an entry for that user in the persist table # valid for 300 seconds if {$username ne ""} { persist add uie $username 300 log "Add persist entry for user \"$username\"" } }
Sign In or Register to comment.