[英]Meteorhack:Cluster subscription call failure
I have an UI app on port 8001 and an app named contract on port 7001. I have 'cluster' installed and working. 我在端口8001上有一个UI应用程序,在端口7001上有一个名为contract的应用程序。我已经安装了“集群”并且可以正常工作。 I have a subscription and insert method defined in 'contract' app.
我在“合同”应用程序中定义了订阅和插入方法。
Cluster.connect("mongodb://<username>:<passwd>@URL");
var options = {
endpoint: "http://localhost:7001",
balancer: "http://localhost:7001", // optional
uiService: "web" // (optional) read to the end for more info
};
Cluster.register("contracts", options);
var Contracts = new Meteor.Collection('contracts');
Meteor.methods({
addContract: addContract,
findContracts: findContracts
});
Meteor.publish("getContracts", function () {
return Contracts.find({});
});
function addContract(c){
var data = {
id: c.id,
type: c.type
};
Contracts.insert(data);
}
function findContracts(){
var contracts = Contracts.find().fetch();
return contracts;
}
I am accessing the methods from an angular controller in my UI app. 我正在从UI应用程序中的角度控制器访问方法。
Cluster.connect(mongodb://<username>:<passwd>@URL"); var options = { endpoint: "http://localhost:8001", balancer: "http://localhost:8001" // optional //uiService: "web" // (optional) read to the end for more info }; Cluster.register("web", options); Cluster.allowPublicAccess("contracts");
UI app controller code
var contractConn = Cluster.discoverConnection('contracts'); contractConn.subscribe('getContracts'); var SubscribedContracts = new Mongo.Collection('SubscribedContracts', {connection: contractConn}); console.log('status', contractConn.status()); vm.contracts = SubscribedContracts.find({}).count(); contractConn.call("findContracts", function(err, result) { if(err) { throw err ; } else { console.log(result); } });
This is what is happening: * I can access methods on the contract server * I can insert or find contracts using these methods * My subscription is not working . 这是正在发生的事情:*我可以访问合同服务器上的方法*我可以使用这些方法插入或查找合同*我的订阅无效 。 fetch on the cursor shows 0 and count shows 0 * Status on the connection shows 'connecting'
光标上的提取显示0,计数显示0 *连接状态显示“正在连接”
What am I doing wrong with my subscription? 我的订阅有什么问题?
Sudi 苏迪
我必须将客户端mongo集合的名称更改为与服务上的集合名称相同的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.