2016-10-19 75 views
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 enter image description here

回答

6

您正在使用您的Worker.js文件中的ConsoleConnector,它將所有機器人對話跟蹤狀態存儲在內存中。這意味着每個節點都有單獨的對話狀態副本,這在多節點體系結構中不起作用。您需要使用使用BotFramework的ChatConnector將對話狀態存儲在您的機器人的一箇中心位置,或者您必須將自定義IBotStorage實施傳遞給UniversalBot。該實現可以使用redis緩存或其他東西集中所有內容。

相關問題