Getting Started Guide: What is Dubbo and how it works

What is Dubbo

Dubbo  is a high-performance distributed service framework developed by Alibaba for remote service invocation and service governance. It has features such as transparent remote calls, load balancing, service registration and discovery, scalability and service governance. Dubbo supports custom expansion of various functions, such as load balancing, protocol, serialization, etc., and provides a large number of service governance functions, such as monitoring, tracking, fault tolerance, and current limiting, to make the operation of the service more stable and reliable. It is an efficient, scalable and reliable distributed service framework solution for building large distributed systems.

What can Dubbo do?

The Dubbo framework has the following functions:

  1. Remote call: The Dubbo framework uses  RPC (Remote Procedure Call) for remote service calls. When implementing service calls in a distributed system, it can make the caller feel as convenient as calling a local service.
  2. Load balancing: Dubbo framework has a variety of load balancing strategies built in, and different load balancing strategies can be selected according to the actual situation, such as random, polling, minimum active number, etc., so that service requests can be distributed to different service providers in a balanced manner, improving Service Availability and Performance.
  3. Service registration and discovery: The Dubbo framework provides the functions of service registration and discovery, which can register services to the registration center, and can also query service information from the registration center, so as to facilitate the dynamic expansion and contraction of services.
  4. Scalability: The Dubbo framework provides an extensible plug-in mechanism, which can customize and expand various functions, such as load balancing, protocol, serialization, etc.
  5. Service governance: The Dubbo framework provides a wealth of service governance functions, such as monitoring, tracking, fault tolerance, and current limiting, which can make the operation of services more stable and reliable.

Dubbo's architecture

The Dubbo framework mainly consists of the following components:

  1. Provider: Publish the service and register the service to the registration center, waiting for the consumer to call.
  2. Consumer: Subscribe to services from the registry, communicate with service providers, and consume services.
  3. Registry: Records information about service providers, as well as the relationship between service providers and service consumers, and helps consumers discover available service instances.
  4. Monitor: Collect Dubbo node performance indicators, service call statistics, etc., so that operation and maintenance personnel can monitor and manage.
  5. Container: The running container of the service.

Application of Dubbo

The following is a Dubbo service startup code sample:

spring.dubbo.application.name=spring-boot-starter-dubbo-demo-consumer
spring.dubbo.registry.address=zookeeper: //localhost:2181
spring.dubbo.protocal.name=dubbo
spring.dubbo.protocol.port=20880
spring.dubbo.scan=com.sunlibin.weathercustomer


3.直接在serviceImpl层通过com.alibaba.dubbo.config.annotation.Reference;

package com.sunlibin.weathercustomer.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.sunlibin.bean.District;
import com.sunlibin.service.RpcDistrictService;
import com.sunlibin.weathercustomer.service.DistrictService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("districtService")
public class DistrictServiceImpl implements DistrictService {

    @Reference
    private RpcDistrictService rpcDistrictService;

    @Override
    public List<District> getAllDistrict() {
        return this.rpcDistrictService.getAllDistrict();
    }

    @Override
    public District getDistrictById(Integer id) {
        return this.rpcDistrictService.getDistrictById(id);
    }
}

Use Apifox to access Dubbo service

Dubbo is actually a remote call scheme of RPC, so accessing Dubbo services can be compared to calling RPC services. We need to use API tools to make interface requests. The following are the brief steps to access Dubbo service through Apifox:

1. Create a new Dubbo request in Apifox, and fill in the corresponding name, access path and request method.

2. Then we arrive at the running page and fill in the parameters of the request body. The format for passing parameters is:

{
   "jsonrpc": "2.0",
   "method": {
   
   {要调用的方法名称}},
   "params": {
   
   {方法所需的参数}},
   "id": {
   
   {请求的唯一标识符}}
}

So we fill in the request parameters in the correct format:

{
   "jsonrpc": "2.0",
   "method": "echo",
   "params": {
       "text": "Dubbo result"
   },
   "id": 18999
}

And click Send to run to get the data returned by the Dubbo service.

3. Click the Send and Run button to get the data returned by the Dubbo server.

in conclusion

The Dubbo framework is an efficient, scalable and reliable distributed service framework solution. It has rich service governance functions and supports custom expansion of various functions, which is suitable for building large-scale distributed systems. Using Apifox to access Dubbo services requires only simple configuration to realize service calls. For more information about the Dubbo framework, click the link below to learn more.

Guess you like

Origin blog.csdn.net/m0_71808387/article/details/131131298