Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build the simplest distributed Dubbo+zookeeper

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to build the simplest distributed Dubbo+zookeeper". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to build the simplest distributed Dubbo+zookeeper" can help you solve the problem.

The simplest distributed construction of Dubbo+zookeeper

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

Distributed architecture:

1. When there are more and more vertical applications, the interaction between applications is inevitable, the core business will be extracted, as an independent service, gradually form a stable service center, the front-end application can respond to the changing market demand more quickly.

two。 At this point, the distributed service framework (RPC) for improving business reuse and integration is the key.

What is Dubbo?

A distributed service framework

A High performance and transparent RPC remote Service invocation Scheme

SOA service governance scheme

Dubbo architecture flowchart

Provider: service provider

Consumer: service consumers

Registry: registry

Monitor: the monitoring center that counts the number and time of service invocation

Call process

0. Start the service provider.

1. Upon startup, the service provider registers the services it provides with the registry.

two。 Service consumers subscribe to the services they need from the registry when they start up.

3. The registry returns a list of service provider addresses to the consumer, and if there is a change, the registry will push the change data to the consumer based on the persistent connection.

4. The service consumer, from the provider address list, chooses one provider to call based on the soft load balancing algorithm, and then chooses another one if the call fails.

5. Service consumers and providers accumulate the number of calls and call time in memory and regularly send statistics to the monitoring center every minute.

Registration center

Service provider: publish to the registry for the services provided.

Service consumers: go to the service center to subscribe to the required services.

For either party, both the service provider and the service consumer may play two roles at the same time, that is, they need to provide services and consume services.

Architecture build case 1.zookpeeper installation

Go to the official website to download zookpeeper

After downloading the package, extract it to a directory, for example: d:\ software\ work\ zookeeper (renamed to zookeeper after decompression)

Change the zoo_sample.cfg file name (D:\ software\ work\ zookeeper\ conf) to zoo.cfg

Mainly change the log directory in the configuration file, as follows:

DataDir=D:\ zookeeper\ data

DataLogDir=D:\ zookeeper\ log

Start

Go to the bin directory and start zkServer.cmd, as shown below:

two。 Create a maven project

The project is divided into four structures.

Dubbo project, main project, mainly import public jar package, etc.

Dubbo-api project, public interface

Dubbo-provider project, service provider

Dubbo-consumer-user and dubbo-consumer projects to serve consumers

(note: each project is independent and father-child relationship is introduced through maven.)

1. Create the maven main project of dubbo

Omit the creation steps, mainly import relevant jar packages, etc. For details, please see the pom.xml given to the source code. For this project, only pom.xml is configured and no other operations are performed.

two。 Create a maven interface project for dubbo-api

Mainly define interfaces and configure pom.xml

3. Create a maven project for dubbo-provider

A service provider that implements the implementation of a public interface, which is hidden from consumers

Join the dependency where the public interface is located

Interface implementation

Declare the service with Spring configuration

Server starts (premise starts zookeeper)

4. Create a maven project for dubbo-consumer-user (can have multiple consumer, configuration keep up)

Service consumers, implementing public interfaces, invoking services

Referencing a service through Spring

Start consumer and invoke the service

5. Run the project in the following order: zookeeper-> dubbo-provider-> dubbo-consumer-user

Running result

3.dubbo-admin building

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 picture:

Service list

Service details

This is the end of the content about "how to build the simplest distributed Dubbo+zookeeper". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report