How To Switch Between CF Instances With Sticky Sessions

Published: {ts '2012-06-26 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/how-to-switch-between-cf-instances-with-sticky-sessions/

If you run a ColdFusion server cluster with sticky sessions you may on occasion need to switch between CF instances in order to perform tasks such as calling an application reload. I do this all the time to switch between different versions of CF(7,8 & 9) on my dev machine. Assuming you are using J2EE sessions here is one method of doing this.

Note 1: You need to be using J2EE session's for this technique to work.

Note 2: This technique creates a new session so any sessioned data from the origin instance will no longer be accessible.

Step 1: Get The Server Instance Name

Before we go about creating our switching mechanism we first need a way to determine which server instance we are one. This is simply done by dropping down into java.

You are currently on server instance: #serverName#

Step 2: Get "server.id" Values

For each CF server instance you create there is a unique server.id value created. This value can be found in the "connector.properties" file defined for each instance. Open this file and note the 4 byte server.id value.

Assuming you installed ColdFusion to the default location of "c:\jrun4" this file for each named server instance would be located at:

c:\jrun4\servers\{servername}\SERVER-INF\connector.properties

Step 3: Update Cookie With The JSESSIONID

In order to switch between server instances all we need to do now is update the JSESSIONID value in the web browser cookie with the server.id value for the instance we want to switch to using the cfcookie tag.

Putting It All Together

So now that we have all the required components lets put them together. Create a file "switcher.cfm" and paste in the code (remembering to substitute in your own server.id values).

You are currently on server instance: #serverName#

To switch to a different CF instance click the relevant link below.

Switch to Instance 1 (da30)
Switch to Instance 2 (c030)