首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何告诉您选择哪个提供商

如何告诉您选择哪个提供商
EN

Stack Overflow用户
提问于 2016-10-19 07:09:28
回答 1查看 88关注 0票数 0

全部:

当我尝试它的请求-响应https://deepstream.io/示例时,我对Deepstream还是个新手

代码语言:javascript
复制
// remote procedure call for "times-three" with 7
client.rpc.make( "times-three", 7, function( err, result ){
  // And get 21 back
  console.log( result );
});

// register as a provider
client.rpc.provide( 'times-three', function( num, response ){
  // ...and respond to requests
  response.send( num * 3 );
});

我想知道如果我打开多个名称相同但逻辑不同的提供程序(例如,我将client.rpc.provide放在几个页面中并全部打开),client.rpc.make应该选择哪一个?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-10-19 17:53:23

Deepstream通过随机选择顺序提供者来执行负载均衡,提供者被选择来满足RPC,如果提供者不愿意处理它,它可以选择拒绝RPC。

如果您的提供程序执行不同的逻辑,最好将它们命名为不同的名称,以区分调用。类似于对不同的请求使用不同的HTTP路径。

举个例子:

代码语言:javascript
复制
// remote procedure call for "times-three" with 7
client.rpc.make( "times-three", 7, function( err, result ){
  // And get 21 back
  console.log( result );
});

// this might be triggered, but will always reject it ( for the sake of this example )
client.rpc.provide( 'times-three', function( num, response ){
  response.reject();
});

// this will always be triggered, either first or second
client.rpc.provide( 'times-three', function( num, response ){
  response.send( num * 3 );
});

// this will never be triggered
client.rpc.provide( 'times-four', function( num, response ){
  response.send( num * 4 );
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40119490

复制
相关文章

相似问题

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