1
集羣后,它不能按預期工作,並一次又一次地問我的名字。爲什麼Microsoft bot框架不可擴展?
我錯過了什麼嗎?
這是我的微軟bot框架的代碼。
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);
}
]);
}
輸出
$ 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
更多信息here