OK, so to get session clustering you need to add some settings to your Application.cfc, here is an example of mine:
component { |
| this.name = "ClusterDemo"; |
| this.sessionType = "application"; |
|
|
| this.datasources["sessionData"] = { |
| class: 'org.gjt.mm.mysql.Driver' |
| , connectionString: 'jdbc:mysql://localhost:3306/sessionData?useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=true' |
| , username: '' |
| , password: "" |
| |
| , storage:true // default: false |
| }; |
|
|
| this.sessionManagement = true; |
| this.sessionStorage = "sessionData" |
| this.sessionCluster = true; |
| |
| } |
Going line by line:
1) First set the application name, this is important to maintain the data correctly.
2) this.sessionType: I am manually setting it to application rather than j2ee here
3) here I create a datasource called sessionData. notice I set the storage:true so it can contain session data
4) Then I setup this.sessionManagement=true (since I do want it to manage sessions)
5) then I tell it where I want it to store sessions, in this case in the sessionData DSN I defined in 3
6) Finally, I want it to cluster them across servers, so just set this.sessioncluster = true.
as long as both of your applications (and they should be the same one!) have this, you can put these servers in a cluster and not even have to do sticky sessions, but just round robin the requests and it all should maintain state.
The downside here is that the OnSessionEnd() method in Application.cfc won’t get triggered anymore since you never know WHEN the session would end as it is not up to each individual server to define that. You can still have something else that reaps the sessions by checking the table in the database which contains an expires column.
I hope this helps!
regards
Mark Drew