Dubbo+zookeeper the simplest distributed structures

Source: Internet
Author: User
Tags zookeeper
Dubbo+zookeeper The simplest distributed structures

Hi, I'm Andy, that's always positive and narcissistic Andy.

Introduction: This example uses Dubbo+zookeeper to build a distributed system, environment jdk1.8

Run Introduction: Start Zookeeper-start service provider-Start service consumer
The code for the entire project has been uploaded to Github,https://github.com/brotherandy/dubbo, welcome to view.

Distributed architecture:
1. When vertical application is more and more, the interaction between applications is unavoidable, the core business is extracted, as an independent service, gradually form a stable service center, front-end application can respond to the changeable market demand more quickly.
2. At this point, the Distributed Service Framework (RPC), which is used to improve business reuse and consolidation, is critical. What is Dubbo? a distributed service framework high-performance and transparent RPC remote Service invocation Scenario SOA Service Governance Solution Dubbo Architecture Flowchart

Provider: service Provider
Consumer: Service Consumers
Registry: Registration Center
Monitor : A monitoring Center for statistics on the number of service invocations and call times

Call Process
0. Start service provider.
1. The service provider registers its own services with the registry at the time of commencement.
2. When starting, the service consumer subscribes to the registry for the services it needs.
3. The registry returns the service provider address list to the consumer, and if so, the registry will push the change data to the consumer based on the long connection.
4. Service consumers, from the provider address list, based on the soft load equalization algorithm, select a provider to invoke, if the call fails, then select another call.
5. Service consumers and providers, in the memory of the cumulative number of calls and call time, timed every minute to send statistical data to the monitoring center.

Registration Center
Service provider: publishes to the registry for the services provided.
Service consumer: The services required to subscribe to the service center.
For any party, whether the service provider or the service consumer is likely to have two roles at the same time, the need to provide services also requires consumer services. Architecture Case 1.zookpeeper Installation

Go to the website to download Zookpeeper

After downloading the package, extract to the directory, such as: D:\software\work\zookeeper (after decompression renamed to zookeeper)
Modify zoo_sample.cfg filename (D:\software\work\zookeeper\conf) to Zoo.cfg
The main change in the configuration file inside the log directory, as follows:
Datadir=d:\zookeeper\data
Datalogdir=d:\zookeeper\log

Start
Go to the Bin directory and start Zkserver.cmd, as shown in figure:
2. Create Maven Project

The project is divided into 4 structures Dubbo Engineering, main engineering, mainly import public jar package and other DUBBO-API engineering, public interface Dubbo-provider Engineering, service provider Dubbo-consumer-user and Dubbo-consumer engineering, Service consumers

(Note: Each project is independent and the parent-child relationship is introduced through Maven)
1. Create a Dubbo MAVEN master project
Create steps omitted, the main import related jar package, etc., please see to the source code Pom.xml, this project temporarily only configure Pom.xml, no other operation

2. Create a DUBBO-API Maven interface project
The main definition interface, and configuration good pom.xml

3. Create a Dubbo-provider maven project
Service provider, realize the realization of public interface, this realization hides to the consumer

Dependencies that join the public interface

Interface implementation

Declaring services with spring configuration

Service initiates (prerequisite startup zookeeper)

4. Create Dubbo-consumer-user Maven project (can have multiple consumer, configure to keep up)
Service consumer, implement common interface, invoke service

Service through Spring Reference

Start consumer, invoke service

5. Run the project, order:zookeeper–> dubbo-provider–> Dubbo-consumer-user

Run results
3.dubbo-admin Build

Provide interface Management Dubbo service

Download Address
https://itmayun.ctfile.com/fs/3011962-230676583

After downloading, put the war package into Tomcat's WebApps directory and start Tomcat

Browser input: http://localhost:8080/dubbo-admin/
Default account: root password: root

Effect Chart:
Services list

Service Details

The code for the entire project has been uploaded to Github,https://github.com/brotherandy/dubbo, welcome to view.

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.