0

All:

I am pretty new to Deepstream, when I try its example of request-response https://deepstream.io/:

// 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 );
});

I wonder if I open multiple provider with same name but different logic(for example I put client.rpc.provide in several pages and open them all), which one should client.rpc.make choose?

Thanks

Kuan
  • 11,149
  • 23
  • 93
  • 201

1 Answers1

1

Deepstream does loadbalancing by a combination of randomly selecting the order providers are selected to fulfill the RPC and giving the provider the option of rejecting the RPC if it isn't willing to process it.

If your providers do different logic it would be best to name them differently to distinguish the calls. Similar to having different HTTP paths for different request.

So for example:

// 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 );
});
yasserf
  • 391
  • 1
  • 7