Dubbo Advanced Chapter _05_DUBBO Service cluster

Source: Internet
Author: User
Tags failover

Cluster purpose: To achieve high availability, fault-tolerant function, the cluster of servers do not put in a physical machine, to disperse nodes, in order to achieve high availability, high fault-tolerant performance, a provider hangs, there are other providers, to ensure that the system normal, stable operation.

First, the Environment preparation

EDU-PROVIDER-01 (192.168.1.121)

EDU-PROVIDER-02 (192.168.1.122)

Connecting to 192.168.1.121:22 ...
Connection established.
To escape to local shell, press ' ctrl+alt+] '.


Last Login:sat Apr 9 04:28:07 from 192.168.1.51
[Root@edu-provider-01 ~]#


Connecting to 192.168.1.122:22 ...
Connection established.
To escape to local shell, press ' ctrl+alt+] '.


Last Login:sat Apr 9 04:28:07 from 192.168.1.51
[Root@edu-provider-02 ~]#


Second, Dubbo service cluster

User Service: Pay-service-user

Trading Services: Pay-service-trade


I started both services at the 121,122 server

[root@edu-provider-01 user]#./service-user.sh start
= = = Start Pay-service-user
[Root@edu-provider-01 user]# CD.
[Root@edu-provider-01 service]# CD trade/
[root@edu-provider-01 trade]#./service-trade.sh start
= = = Start Pay-service-trade


[root@edu-provider-02 user]#./service-user.sh start
= = = Start Pay-service-user
[Root@edu-provider-02 user]# CD.
[Root@edu-provider-02 service]# CD trade/
[root@edu-provider-02 trade]#./service-trade.sh start
= = = Start Pay-service-trade

In the Dubboadmin management console, you can see that the services to both machines are registered successfully


Here I can check the transaction information


I'm going to turn off the 121 trading service.

[root@edu-provider-01 trade]#./service-trade.sh stop
= = = Stop Pay-service-trade

[Root@edu-provider-01 trade]# Ps-ef | grep pay
Root 2803 1 8 06:33 pts/0 00:00:50/usr/jdk/jre/bin/java-xms128m-xmx512m-jar Pay-service-user.jar
Root 2980 2705 0 06:43 pts/0 00:00:00 grep pay
[Root@edu-provider-01 trade]#

Here I can still query the transaction information

I'll turn off 122 of the trading service.

[root@edu-provider-02 trade]#./service-trade.sh stop
= = = Stop Pay-service-trade

[Root@edu-provider-02 trade]# Ps-ef | grep pay
Root 2639 1 7 06:34 pts/1 00:00:51/usr/jdk/jre/bin/java-xms128m-xmx512m-jar Pay-service-user.jar
Root 2816 2592 0 06:46 pts/1 00:00:00 grep pay
[Root@edu-provider-02 trade]#

I'm going to have an exception when I check the transaction information.


I opened the transaction service on the 121 service, but also can inquire the transaction information

[root@edu-provider-01 trade]#./service-trade.sh start
= = = Start Pay-service-trade
[Root@edu-provider-01 trade]#


Third, Dubbo service fault tolerant configuration-Cluster fault tolerant mode

<dubbo:service> provider configuration label, coarse granularity

Example:<!--when a property of Protocolconfig and ServiceConfig is not configured, this default value is used--
<dubbo:provider timeout= "30000" threadpool= "fixed" threads= "[]" accepts= "/>"


<dubbo:service>: Service Release label, example, configure fault tolerance on this, granular <!--provide service interface--
<dubbo:service retries= "0" interface= "edu.pay.facade.trade.service.PaymentFacade" ref= "Paymentfacade"/>


<dubbo:consumer> consumer-side tags, application of a single consumer configuration, coarse granularity
Example: <dubbo:consumer timeout= "8000" retries= "0"/>


Configure fault tolerance on this, fine grained <dubbo:reference >

<!--Call Account service--
<dubbo:reference interface= "Edu.pay.facade.account.service.AccountTransactionFacade" id= " Accounttransactionfacade "check=" false "/>



Property: Cluster Type: string


is required: Optional default value: Failover


Function: Performance tuning cluster mode: Optional: failover/failfast/failsafe/failback/forking

1, Failover Cluster
Failed to automatically switch, when the failure occurs, retry the other server. (the default) is typically used for read operations, but retries result in a longer delay. The number of retries can be set by retries= "2" (excluding the first time).
<dubbo:service retries= "2"/>
Or:
<dubbo:reference retries= "2"/>


Or:
<dubbo:reference>
<dubbo:method name= "Findfoo" retries= "2"/> </dubbo:reference>

2, Failfast Cluster
Fast failure, only one call is initiated, failure immediately error. Typically used for non-idempotent write operations, such as New records.
<dubbo:service cluster= "FailFast"/>
Or:
<dubbo:reference cluster= "FailFast"/>

3.Failsafe Cluster

Fail-safe, directly ignored when an exception occurs, usually for operations such as writing audit logs

<dubbo:service cluster= "failsafe"/> or

<dubbo:reference cluster= "Failsafe"/>

4.Failback Cluster

Failure auto-recovery, background logging failed requests, timed re-sending, typically used for message notification operations.

<dubbo:service cluster= "failback"/>

Or

<dubbo:reference cluster= "failback"/>


5.Forking Cluster

Invoking multiple services in parallel, as long as a successful return, is typically used to require higher read operations in real time, but requires more server resources to be wasted. The maximum number of concurrent numbers can be set by forks= "2".

<dubbo:service cluster= "Forking" >

Or

<dubbo:reference cluster= "forking"/>




In the actual project, in the production environment, we can design the service interface with failover mode, follow the interface isolation principle, the query service and the write operation service are isolated,

Query interface We can configure retries= "2"

In the Write interface we configure retries= "0", if not set to 0, time-out, will reconnect, there will be repeated write, so when using failover mode, we have to read and write interface isolation, and write operation interface retries=0

label

Label



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.