I am making a dockerized services-based application. Some of the services will be written in meteor, some won't.
我正在制作一个基于服务的dockerized应用程序。有些服务将用流星写,有些则不会。
One of the services is a registration service, where users can register for the platform.
其中一项服务是注册服务,用户可以在该服务中注册该平台。
When doing microservices, normally I do the following:
在做微服务时,通常我会做以下事情:
var MyService = DDP.connect(service_url);
var MyOtherService = DDP.connect(other_service_url);
var RegistrationService = DDP.connect(registration_service_url);
What I want to do is use the loginWithFacebook
method. The issue is that using Meteor.loginWithFacebook
on the frontend will invoke its backend methods on the main frontend server.
我想要做的是使用loginWithFacebook方法。问题是在前端使用Meteor.loginWithFacebook将在主前端服务器上调用其后端方法。
However, I want to invoke its backend methods on the RegistrationService server (which has the relevant packages). The reason is because I am using the Accounts.onCreateUser
hook to do extra stuff, and also because I want to keep the registration service separate from the frontend.
但是,我想在RegistrationService服务器(具有相关包)上调用其后端方法。原因是因为我使用Accounts.onCreateUser挂钩做额外的事情,还因为我想保持注册服务与前端分开。
Just for clarity, even though it is not correct, imagine I have this:
为了清楚起见,即使它不正确,想象一下我有这个:
'click #facebook-login': function() {
Meteor.loginWithFacebook(data, callback)
}
However, I want the loginWithFacebook
method to use the server-side methods from RegistrationService
when calling the client-side method .loginWithFacebook, so I actually want to do something to the effect of the following:
但是,我希望loginWithFacebook方法在调用客户端方法.loginWithFacebook时使用来自RegistrationService的服务器端方法,所以我实际上想要做一些事情来实现以下效果:
'click #facebook-login': function() {
RegistrationService.loginWithFacebook(data, callback)
}
Any help on this will be greatly appreciated. Thank you!
任何有关这方面的帮助将不胜感激。谢谢!
2 个解决方案
#1
I believe you are looking for DDP.connect. Basically underneath meteor all calls to the server from the client and all communication from the server to the client use Distributed Data Protocol. (https://www.meteor.com/ddp) As the documentation points out by default a client opens a DDP connection to the server it is loaded from. However, in your case, you'd want to use DDP.connect to connect to other servers for various different tasks, such as a registration services server for RegistrationService. (http://docs.meteor.com/#/full/ddp_connect) As a simplified example you'll be looking to do something like this:
我相信您正在寻找DDP.connect。基本上在meteor下面,所有从客户端调用服务器,从服务器到客户端的所有通信都使用分布式数据协议。 (https://www.meteor.com/ddp)正如文档默认指出的那样,客户端打开与其加载的服务器的DDP连接。但是,在您的情况下,您希望使用DDP.connect连接到其他服务器以执行各种不同的任务,例如RegistrationService的注册服务服务器。 (http://docs.meteor.com/#/full/ddp_connect)作为一个简单的例子,你将寻求做这样的事情:
if (Meteor.isClient) {
var registrationServices = DDP.connect("http://your.registrationservices.com:3000");
Template.registerSomething.events({
'click #facebook-login': function(){
registrationServices.call('loginWithFacebook', data, function(error, results){ ... }); // registration services points to a different service from your default.
}
});
}
Don't forget that you can also have various DDP.connect's to your various microservices. These are akin to web service connections in other applications.
不要忘记,您还可以将各种DDP.connect连接到各种微服务。这些类似于其他应用程序中的Web服务连接。
#2
You can maybe achieve connection through your other service by specifying the service's remote connection to Accounts
and Meteor.users
:
您可以通过指定服务与Accounts和Meteor.users的远程连接,通过其他服务实现连接:
var RegistrationService = DDP.connect(registration_service_url);
Accounts.connection = RegistrationService;
Meteor.users = new Meteor.Collection('users',{connection: RegistrationService});
Then would call Meteor.loginWithFacebook
and it should use the other app's methods for logging in.
然后将调用Meteor.loginWithFacebook,它应该使用其他应用程序的方法登录。
#1
I believe you are looking for DDP.connect. Basically underneath meteor all calls to the server from the client and all communication from the server to the client use Distributed Data Protocol. (https://www.meteor.com/ddp) As the documentation points out by default a client opens a DDP connection to the server it is loaded from. However, in your case, you'd want to use DDP.connect to connect to other servers for various different tasks, such as a registration services server for RegistrationService. (http://docs.meteor.com/#/full/ddp_connect) As a simplified example you'll be looking to do something like this:
我相信您正在寻找DDP.connect。基本上在meteor下面,所有从客户端调用服务器,从服务器到客户端的所有通信都使用分布式数据协议。 (https://www.meteor.com/ddp)正如文档默认指出的那样,客户端打开与其加载的服务器的DDP连接。但是,在您的情况下,您希望使用DDP.connect连接到其他服务器以执行各种不同的任务,例如RegistrationService的注册服务服务器。 (http://docs.meteor.com/#/full/ddp_connect)作为一个简单的例子,你将寻求做这样的事情:
if (Meteor.isClient) {
var registrationServices = DDP.connect("http://your.registrationservices.com:3000");
Template.registerSomething.events({
'click #facebook-login': function(){
registrationServices.call('loginWithFacebook', data, function(error, results){ ... }); // registration services points to a different service from your default.
}
});
}
Don't forget that you can also have various DDP.connect's to your various microservices. These are akin to web service connections in other applications.
不要忘记,您还可以将各种DDP.connect连接到各种微服务。这些类似于其他应用程序中的Web服务连接。
#2
You can maybe achieve connection through your other service by specifying the service's remote connection to Accounts
and Meteor.users
:
您可以通过指定服务与Accounts和Meteor.users的远程连接,通过其他服务实现连接:
var RegistrationService = DDP.connect(registration_service_url);
Accounts.connection = RegistrationService;
Meteor.users = new Meteor.Collection('users',{connection: RegistrationService});
Then would call Meteor.loginWithFacebook
and it should use the other app's methods for logging in.
然后将调用Meteor.loginWithFacebook,它应该使用其他应用程序的方法登录。