0

全部:

当我尝试请求响应https://deepstream.io/的示例时,我对 Deepstream 还是很陌生:

// 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选择哪一个?

谢谢

4

1 回答 1

1

Deepstream 通过随机选择订单供应商来完成 RPC 并让供应商选择拒绝 RPC(如果它不愿意处理它)来进行负载平衡。

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

例如:

// 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 );
});
于 2016-10-19T09:53:22.523 回答