1

我们正在将我们的应用程序从 Rackspace 转移到 Modulus。我们有 2 个使用 meteorhacks:cluster 包配置为微服务的应用程序。似乎 Meteor 方法(服务器 1 到服务器 2)调用正在工作,但流星订阅(客户端 2 到服务器 1)不起作用。我想弄清楚这是否是跨域请求问题。

// 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 上运行。

4

1 回答 1

1

我没有使用meteorhacks:cluster,但我正在为我的meteor 应用程序运行微服务。它在 DO 上,所以设置可能会有所不同,但这就是我的做法。

我正在使用响应式发布来帮助服务器端响应

// 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({})
})

这个想法是您的客户端只与它自己的服务器通信,但服务器随后会与您的所有其他微服务通信。这为您提供了允许服务器在专用网络上相互通信的更高安全性(因为我有我的数字海洋设置)。

让服务器通过专用网络相互通信是最好的安全性,服务器之间的网络延迟几乎为零。像这样设置也意味着您只需要担心客户端浏览器和面向 Web 的应用程序/服务之间的粘性会话。

这可能会或可能不会回答您的问题,但希望它能让您对设置架构有所了解。

于 2016-01-14T19:25:14.507 回答