我们正在将我们的应用程序从Rackspace转移到Modulus。我们有2个应用程序使用meteorhacks配置为微服务:集群包。似乎Meteor方法(server1到server2)调用正在工作,但Meteor订阅(client2到server1)不起作用。我想弄清楚它是否是跨域请求问题。
// https://github.com/meteorhacks/cluster#microservices
//server2/app.js
Cluster.register(process.env.APP_NAME,{endpoint:process.env.ROOT_URL});
mainApp = Cluster.discoverConnection("server1");
Cluster.allowPublicAccess("server1");
//client2/app.js
mainApp = Cluster.discoverConnection("server1");
ContentLibrary= new Meteor.Collection('content_library', {connection:mainApp,idGeneration : 'MONGO'});
//client2/home.js
mainApp.subscribe('contentDocuments','all',function(e){
if(!e)
doSomething();//Never gets called
});
//server1/publish.js
Meteor.publish("contentDocuments", function(){
return ContentLibrary.find({});
}
永远不会填充客户端上的ContentLibrary集合。
我们的应用程序可以按预期在Rackspace上运行。
答案 0 :(得分:1)
我没有使用meteorhacks:群集,但我正在为我的流星应用程序运行微服务。它在DO上,所以设置可能会有所不同,但这就是我如何做的。
我使用reactive-publish来帮助提升服务器端反应性
// client ------
/server/lib/ddp-setup.js
ContentLibrary = DDP.connect('10.123.455.332:3000')
/server/publications.js
Content = new Mongo.Collection('content', {connection: ContentLibrary})
Meteor.publish('content', function(opts){
check(opts, Object)
this.autorun(()=>{
let sub = ContentLibrary.subscribe('content', opts)
if( sub.ready() ){
return Content.find({})
}
})
})
// server1 @ 10.123.455.332:3000 -------
/server/publications.js
Meteor.publish('content', function(opts){
check(opts, Object)
// do something with opts...
return Content.find({})
})
我们的想法是,您的客户端只与自己的服务器通信,但服务器会与您的所有其他微服务进行通信。这为您提供了更高的安全性,允许服务器在专用网络上相互通信(因为我的设置是数字海洋)。
让服务器通过专用网络相互通信是最好的安全性,服务器之间的网络延迟几乎为零。像这样设置也意味着你只需要担心客户端浏览器和面向网络的应用程序/服务之间的粘性会话。这可能会也可能不会回答您的问题,但希望它能让您深入了解如何设置架构。