When the cluster call fails, Dubbo provides a variety of fault tolerance schemes, and the default is failover retry.
Each node relationship:
Invoker
is an abstraction of Provider
that can call Service
, Invoker
encapsulates Provider
address and Service
interface informationDirectory
represents multiple Invoker
, which can be regarded as List<Invoker>
, but different from List
, its value may change dynamically, such as the registration center pushing changesCluster
disguises multiple Invoker
in Directory
as an Invoker
, which is transparent to the upper layer. The masquerading process includes fault-tolerant logic. After the call fails, try another oneRouter
is responsible for selecting subsets from multiple Invoker
according to routing rules, such as read-write separation, application isolation, etc.LoadBalance
is responsible for selecting a specific one from multiple Invoker
s for this call. The selection process includes a load balancing algorithm. After the call fails, it needs to be re-selectedYou can expand the cluster fault-tolerant strategy by yourself, see: Cluster Expansion
Automatic switching on failure, when a failure occurs, retry other servers. Usually used for read operations, but retries can introduce longer delays. The number of retries can be set by retries="2"
(excluding the first time).
The number of retries is configured as follows:
<dubbo:service retries="2" />
or
<dubbo:reference retries="2" />
or
<dubbo:reference>
<dubbo:method name="findFoo" retries="2" />
</dubbo:reference>
Fail fast, only one call is made, and an error will be reported immediately if it fails. Usually used for non-idempotent write operations, such as adding new records.
Fail safe, when an exception occurs, just ignore it. Typically used for operations such as writing to audit logs.
The failure is automatically recovered, and the failed request is recorded in the background and resent at regular intervals. Typically used for message notification operations.
Call multiple servers in parallel, and return as long as one succeeds. It is usually used for read operations with high real-time requirements, but more service resources need to be wasted. The maximum parallelism can be set by forks="2"
.
Broadcast calls all providers one by one, and if any one reports an error, it will report an error. Usually used to notify all providers to update local resource information such as cache or logs.
Now in the broadcast call, you can configure the failure ratio of the node call through broadcast.fail.percent. When this ratio is reached, the BroadcastClusterInvoker No other nodes will be called, and an exception will be thrown directly. broadcast.fail.percent ranges from 0 to 100. By default, an exception is thrown when all calls fail. broadcast.fail.percent only controls whether to continue to call other nodes after failure, and does not change the result (if any node reports an error, it will report an error). broadcast.fail.percent parameter Effective in dubbo2.7.10 and above.
Broadcast Cluster configuration broadcast.fail.percent.
broadcast.fail.percent=20 means that when 20% of the nodes fail to call, an exception will be thrown, and no other nodes will be called.
@reference(cluster = "broadcast", parameters = {"broadcast. fail. percent", "20"})
2.1.0
started to supportCalls the currently available instance (only one is called), or throws an exception if no instance is currently available. Usually used in scenarios that do not require load balancing.
Aggregate the call results in the cluster and return the result, usually used together with group. Aggregate the results by grouping and return the aggregated results, such as menu services, use group to distinguish multiple implementations of the same interface, now the consumer needs to call once from each group and return the results, and return the results after merging, so that You can implement aggregated menu items.
In the scenario of multi-registry subscription, load balancing between registry clusters. There are four strategies for address selection between multiple registries:
preferred="true"
The address of the registration center will be selected first<dubbo:registry address="zookeeper://127.0.0.1:2181" preferred="true" />
<dubbo:registry address="zookeeper://127.0.0.1:2181" zone="beijing" />
<dubbo:registry id="beijing" address="zookeeper://127.0.0.1:2181" weight="100" />
<dubbo:registry id="shanghai" address="zookeeper://127.0.0.1:2182" weight="10" />
Follow the example below to configure cluster mode on the service provider and consumer
<dubbo:service cluster="failsafe" />
or
<dubbo:reference cluster="failsafe" />