Principles of distributed systems, what is RPC, and Dubbo and zookeeper

Distributed system A
distributed system is a system composed of a group of computer nodes that communicate through a network and coordinate work to complete a common task. The emergence of distributed systems is to use cheap, ordinary machines to complete calculations and storage tasks that a single computer cannot complete. Its purpose is to use more machines and process more data.
Distributed systems are software systems built on the network.
First of all, it needs to be clear that only the processing power of a single node cannot meet the increasing computing and storage tasks, and when the hardware upgrades (adding memory, adding disks, using better cpu) are so high that the gains outweigh the losses, the applications are also too expensive. When we can’t optimize further, we need to consider the distributed system, because the problem to be solved by the distributed system is the same as the stand-alone system, and because the distributed system has multiple nodes, through network communication, many stand-alone systems will not be introduced. In order to solve these problems, more mechanisms, protocols, and more problems will be introduced.
Dubbo documents.
With the development of the Internet, the scale of website applications continues to expand. The conventional vertical application architecture can no longer cope with it. Distributed service architecture and Mobile computing architecture is inevitable, and there is an urgent need for a governance system to ensure the orderly evolution of the architecture.
Single application architecture.
When website traffic is very small, only one application is needed. All functions are deployed together to reduce deployment nodes and costs. At this time, it is used to simplify The data access framework (ORM)
Insert picture description herefor adding, deleting, checking and modifying workloads is critically applicable to small websites and small management systems. All functions are deployed to one function. It is simple and easy to use.
Disadvantages
1, performance expansion is more difficult
2, and collaborative development problems
3, It is not conducive to upgrade and maintain the
vertical application architecture.
When the amount of visits gradually increases, the acceleration caused by the increase of a single application machine is getting smaller and smaller. The application is divided into several unrelated applications to improve efficiency. At this time, it is used to
accelerate the front-end Web framework (mvc) for page development is the key
Mobile computing architecture
When more and more services, capacity evaluation, small service resource waste and other problems gradually appear, at this time, a dispatch center is added to manage the cluster capacity in real time based on access pressure to improve cluster utilization. At this time, it is used to improve machine utilization. Rate resource scheduling and governance center is the key Insert picture description hereRPC
What is RPC
RPC refers to remote scheduling, is an inter-process communication method, it is a technical idea, not a specification, it allows the program to
call another address space (usually The procedure or function on another machine sharing the network, instead of the programmer explicitly coding the details of this remote call,
that is, whether the programmer calls a local or remote function, essentially the written call local or remote function , The calling code written is basically the same

That two servers A, B, A an application deployed on the server you want to call functions / methods provided by the application server B, because it is not a memory empty
room, can not be called directly, the need to express the semantics of the call through the network And communicate the called data. Why RPC? Is not within a process, or even
a local call is completed by way of a computer needs, such as communication between different systems, even the communication between different organizations, due to the computing power required transverse
to the extension, The application needs to be deployed on a cluster composed of multiple machines. RPC is to call remote functions like calling local functions;
Dubbo concept
What is dubbo?
Apache Dubbo I'dAbeu| is a high-performance, lightweight open source Java RPC framework, which provides three core capabilities: Remote method invocation of interfaces
, intelligent fault tolerance and load balancing, and automatic service registration and discovery.
The
Insert picture description here
Insert picture description here
Insert picture description here
suffix of zookeeper sh installed on windows is Linux and
Insert picture description here
Insert picture description here
no error will be reported when you open it at the moment!
Insert picture description here
Opening the server will report an error, just like modifying the configuration variables on Linux.
Insert picture description here
At this point, open the client and
Insert picture description here
simply test that our zookeeper is installed!
Dubbo briefly introduces
Insert picture description here
Service Provider (Provider): The service provider that exposes the service. When the service provider starts, it registers the service it provides with the registry.
Service consumers (Consumer): call the remote service consumer services, consumer services at startup, they need to subscribe to the service registry, service consumer
charges were, from the provider address list, based on the soft load balancing algorithm, Choose one provider to call, if the call fails, choose another one to call.
Registry: The registry returns a list of service provider addresses to consumers. If there is a change, the registry will push the change data to the
consumer
monitoring center (Monitor) based on the long connection : service consumers and providers, in memory Accumulate the number of calls and call time, and send statistical data to the monitoring
center every minute. The
call relationship description The
service container is responsible for starting, loading and running the service provider.
When the service provider starts, it registers the service it provides with the registration center.
When a service consumer is started, he subscribes to the registry for the service he needs.

The registration center returns the service provider address list to the consumer. If there is a change, the registration center will push the change data to the consumer based on the long connection change.
The service consumer, from the provider address list, based on the soft load balancing algorithm, selects the provider to call, and if the call fails, select another call.
Service consumers and providers accumulate the number of calls and call time in the memory, and send statistical data to the monitoring center every minute.

Installing Dubbo is to let you see who is consuming what. It can be said to be a visual tool. The
first step is to
Insert picture description here
download a Springboot project. Just package it.
Don’t let it run and test
mvn clean package -Dmaven.test.skip =true After
generating the jar package, open the zookeeper and double-click the jar package! !
Insert picture description here
Visit this port number, log in to root, and root can log in. The
Insert picture description here
effect is actually equivalent to visualization!
Springboot integrates dubbo and zookeeper
first step
Insert picture description here

Step 2:
add Springboot module
Insert picture description here

Consumer structure
Insert picture description here
Simple service

package com.jj.proviser.service;

public interface proviser {
    
    
//    返回字符串的方法
    public String demo();
}

Implementation class

package com.jj.proviser.service;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

//加入注解
@Component   //要用这个万能注解,应为 dubbo 的service 的注解和原来的service 一样,怕冲突
@Service
public class proviserimpl implements proviser{
    
    
    @Override
    public String demo() {
    
    
        return "我是娇娇的第一个服务端!";
    }
}

yml server

#配置端口号
server.port=8081
#服务中心的名字
dubbo.application.name=proviser-server
#注册中心的地址
dubbo.registry.address=zookeeper://127.0.0.1:2181
#那些要被注册
dubbo.scan.base-packages=com.jj.proviser.service

rely

<!--dubbo依赖-->
        <!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.6</version>
        </dependency>
        <!--zookeeper客户端依赖-->
        <!-- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>``
        </dependency>
        <!--日志冲突-->
        <!-- 引入zookeeper -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.14</version>
            <!--排除这个slf4j-log4j12-->
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

The startup project can see the provider we wrote on dubbo, check the details to
Insert picture description here
Insert picture description here
configure the consumer
Insert picture description here

package com.jj.proviser.service;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

@Service
public class Comsumer {
    
    

//想要拿到 提供者的,需要去注册中心拿到
    @Reference //引用 pom 坐标可以, 也可以定义路径相同的接口
    proviser proviser;
    public void buy()
    {
    
    

        String demo = proviser.demo();
        System.out.println("我是娇娇的第一个demo = " + demo);
    }
}

marl

#配置端口号
server.port=8082
#消费者取哪里拿到需要
dubbo.application.name=consumer
#注册中心的地址
dubbo.registry.address=zookeeper://127.0.0.1:2181

Test effect
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46937429/article/details/111880982
Recommended