All Products
Document Center

SOFARPC Routing Policy

Last Updated: Aug 17, 2020

The most important part in RPC is to obtain the service provider’s address. There are two policies to get them as follows:


SOFARegistry works as the software load balancer (SLB), which implements load balancing through software. When calling a service, a consumer selects an address from the list pushed by SOFARegistry to the local cache, and invokes the service provided at that address.

SOFARPC uses a service publishing (ServicePublish) and reference model (ServiceReference), where SOFARegistry dynamically perceives service publishing and pushes the service address list to consumers that has referenced the service. At the same time, SOFARegistry updates the available service list in consumers’ local cache and uses the load balancing algorithm to select an available address for remote communication.

With the SOFARegistry, there is no need of hardcoded address in SOFARPC.

Please see the following figure for principle of SLBSLB

Direct Link

In development and test environments, developers often need a direct link to bypass SOFARegistry and test only a specific service provider. Such function can be achieved through the configuration of test-url and target-url.

The application scenarios of direct link can be divided as two types as follows:

  • Local Environment: achieved through configuration of run_mode=TEST and test-url.
  • Online Environment: recommended to use target-url.


    • Once test-url or target-url is configured, SLB will be invalid.
    • If run_mode=TEST & test-url and target-url are configured concurrently, test-url will be effective finally.

Local Environment

The configuration procedure is as follows:

  1. write run_mode=TEST in
  2. when service reference is needed, add a global-attrs tag in sofa:binding.bolt and set the value of test-url to the target address. Please see the demo below for the whole configuration.
    1. <sofa:reference id="sampleService" interface="">
    2. <sofa:binding.bolt>
    3. <sofa:global-attrs test-url=""/>
    4. </sofa:binding.bolt>
    5. </sofa:reference>

Online Environment

target-url is recommended other than test-url with the cloud environment. Please see the demo below for the whole configuration.

  1. <sofa:reference id="sampelService" interface="">
  2. <sofa:binding.bolt>
  3. <sofa:route target-url="target-url:12200"/>
  4. </sofa:binding.bolt>
  5. </sofa:reference>