Reputation: 7742
After clustering it does not work as expected and ask me name again and again.
Am I missing something?
Here is my code for microsoft bot framework.
server.js
var worker = require('./worker');
var cluster = require('cluster');
var spawnWorker = function() {
worker.createServer();
};
var createCluster = function() {
if(cluster.isMaster) {
var cpus = require('os').cpus().length;
for(var i = 0; i < cpus; i++) {
cluster.fork();
}
cluster.on('online', function(wkr) {
console.log('Worker started', wkr.process.pid);
});
cluster.on('exit', function(wkr) {
console.log('Worker died, respawing', wkr.process.pid);
cluster.fork();
});
} else {
spawnWorker();
}
};
createCluster();
worker.js
exports.createServer = function(){
var builder = require('botbuilder');
var connector = new builder.ConsoleConnector().listen();
var bot = new builder.UniversalBot(connector);
bot.dialog('/', [
function (session) {
builder.Prompts.text(session, process.pid+': Hi! What is your name?');
},
function (session, results) {
session.send(process.pid+':Hello %s!', results.response);
}
]);
}
Output
$ node server.js
Worker started 8540
Worker started 8068
Worker started 6020
Worker started 4244
8540: Hi! What is your name?
abc
8068: Hi! What is your name?
prq
6020: Hi! What is your name?
lmn
4244: Hi! What is your name?
xyz
More information here
Upvotes: 1
Views: 508
Reputation: 1946
You're using the ConsoleConnector in your Worker.js file which stores all of the bots conversation tracking state in memory. That means each node has a separate copy of the conversation state which won't work in a multi-node architecture. You need to either use the ChatConnector which uses the BotFramework to store the conversation state in one central place for your bot or you will have to pass a custom IBotStorage implementation to your UniversalBot. That implementation could use a redis cache or something to centralize everything.
Upvotes: 6