The most important part in RPC is to obtain the service provider’s address. There are two policies to get them as follows:
SLB
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
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
andtest-url
. - Online Environment: recommended to use
target-url
.Note:
- Once
test-url
ortarget-url
is configured, SLB will be invalid. - If
run_mode=TEST & test-url
andtarget-url
are configured concurrently,test-url
will be effective finally.
- Once
Local Environment
The configuration procedure is as follows:
- write
run_mode=TEST
inapplication.properties
. - when service reference is needed, add a
global-attrs
tag insofa:binding.bolt
and set the value oftest-url
to the target address. Please see the demo below for the whole configuration.<sofa:reference id="sampleService" interface="com.alipay.test.SampleService">
<sofa:binding.bolt>
<sofa:global-attrs test-url="127.0.0.1:12200"/>
</sofa:binding.bolt>
</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.
<sofa:reference id="sampelService" interface="com.alipay.test.SampleService">
<sofa:binding.bolt>
<sofa:route target-url="target-url:12200"/>
</sofa:binding.bolt>
</sofa:reference>