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 SLB
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
The application scenarios of direct link can be divided as two types as follows:
- Local Environment: achieved through configuration of
- Online Environment: recommended to use
target-urlis configured, SLB will be invalid.
run_mode=TEST & test-urland
target-urlare configured concurrently,
test-urlwill be effective finally.
The configuration procedure is as follows:
- when service reference is needed, add a
sofa:binding.boltand set the value of
test-urlto the target address. Please see the demo below for the whole configuration.
<sofa:reference id="sampleService" interface="com.alipay.test.SampleService">
target-url is recommended other than
test-url with the cloud environment. Please see the demo below for the whole configuration.
<sofa:reference id="sampelService" interface="com.alipay.test.SampleService">