socket.io - How to enable sticky sessions on a LoopbackJS app running on CloudFoundry/Bluemix -


i have loopbackjs app deployed on ibm bluemix , horizontally scaled across 3 instances. app uses socket.io implement chat system.

i'd activate sticky sessions each request coming same client routed same app instance.

i know sticky sessions supposed avoided according 12 factors. seems solution in order have socket.io working multiple nodes.

as stated here, seems need set jsessionid session cookie in loopback application.

i did following in server.js of loopbackjs app:

var session = require('express-session'); app.use(session({   secret: 's3cur3',   name: 'jsessionid',   proxy: true,   resave: true,   saveuninitialized: true })); 

after making change, when issue request loopback app, can see 2 cookies set in response headers:

set-cookie:__vcap_id__=988ce9aa9b7f49cdb31d04f697d892b6024579565ea443589ed10e7a4c1c05f0; path=/; httponly, jsessionid=s%3adb3ksqgzfkweg39wrlkcsb3awpazcogd.tca1vybvb5dqemjxds%2blxuj207wnc7ugms5bpjzq9xc; path=/; httponly; secure set-cookie:jsessionid=s%3adb3ksqgzfkweg39wrlkcsb3awpazcogd.tca1vybvb5dqemjxds%2blxuj207wnc7ugms5bpjzq9xc; path=/; httponly 

anyway, when issue request again same browser, can see in logs on bluemix side request served different app instance.

i'm inexperienced on subjects, appreciate advice configure sticky sessions.

per https://docs.cloudfoundry.org/concepts/http-routing.html#sessions

"on subsequent requests, client must provide both jsessionid , vcap_id cookies. cf routing tier uses vcap_id forward client requests same application instance every time."

e.g. pick vcap_id , supply alongside jsessionid


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -