Forum Discussion
Hi sidkhan,
a very generic (aka. not very much optimized) iRule based on the provided application logic may look like that...
when HTTP_REQUEST {
STREAM::disable
if { [set sessionid [URI::query [HTTP::uri] "sessionid"]] ne "" } then {
log local0.debug "Found incomming Session ID: [URI::query [HTTP::uri] "sessionid"]"
persist uie $sessionid
}
}
when HTTP_RESPONSE {
if { [HTTP::header value "Content-Type"] equals "application/json" } then {
STREAM::expression {@"SessionId": "([a-z0-9-]+)",@}
STREAM::enable
}
}
when STREAM_MATCHED {
if { [set sessionid [getfield [STREAM::match] {"} 4]] ne "" } then {
log local0.debug "Extracted outgoing Session ID: $sessionid"
eval "persist add uie \$sessionid 900"
}
}
The iRule will
persist
incomming requests based on the value of the Query-String parameter "sessionid" .
If the persist database does not hold an entry for that value, or if the client does not send any "sessionid" parameter, the request will be balanced based on your pool settings.
The iRule will furthermore
STREAM
inspect every outgoing JSON response for a string in the regex format of "SessionId": "([a-z0-9-]+)",
. If a match is found, the iRule would extract the ([a-z0-9-]+)
portion and create/update the persistence database with the currently selected pool member IP.
Note: You MUST apply a STREAM and ONECONNECT profile to your Virtual Server in order to make this iRule work. You may use the defaults profiles without any further configuration.
Note: You may monitor the functionality with LTMs log files and using the TMSH command
. Once you have verified the functionality of this iRule, you may want to remove the individual log lines from the script...(tmsh) show ltm persistence persist-records
Cheers, Kai