首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Modulus微服务订阅不起作用

Modulus微服务订阅不起作用
EN

Stack Overflow用户
提问于 2016-01-08 00:59:08
回答 1查看 155关注 0票数 1

我们正在将我们的应用程序从Rackspace迁移到Modulus。我们有两个应用程序被配置为微服务,使用的是meteorhacks:cluster package。似乎流星方法(server1到server2)调用正常,但流星订阅(client2到server1)不起作用。我正在尝试弄清楚这是否是跨域请求问题。

代码语言:javascript
复制
// 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上的运行符合预期。

EN

回答 1

Stack Overflow用户

发布于 2016-01-15 03:25:15

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

我正在使用reactive-publish来帮助处理服务器端的反应性

代码语言:javascript
复制
// 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的应用程序/服务之间的粘性会话。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34660949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档