The starting point of microservices --- DUBBO (quick start, getting started, springboot build environment) (a high-performance RPC framework, 3.2.0-beta.4)

1. Introduction to DUBBO

1.1. What is DUBBO?

Apache Dubbo is an RPC service development framework, which is used to solve service governance and communication problems under the microservice architecture. It officially provides multi-language SDK implementations such as Java and Golang. The microservices developed using Dubbo have native remote address discovery and communication capabilities with each other. Using the rich service governance features provided by Dubbo, service governance demands such as service discovery, load balancing, and traffic scheduling can be realized. Dubbo is designed to be highly scalable, and users can easily implement various custom logics for traffic interception and location selection.
In the era of cloud native, Dubbo has successively derived Dubbo3, Proxyless Mesh and other architectures and solutions, and has carried out comprehensive upgrades in several major directions such as ease of use, ultra-large-scale microservice practice, cloud native infrastructure adaptation, and security.

Dubbo's open source story.

Apache Dubbo was originally designed and developed to solve Alibaba's internal microservice architecture problems. For more than ten years, it has been widely used in many business systems within Alibaba. As early as 2008, Alibaba donated Dubbo to the open source community. It quickly became the de facto standard framework for the selection of domestic open source service frameworks and has been widely used in the industry.
insert image description here

In 2017, Dubbo was officially donated to the Apache Software Foundation and became a top Apache project, starting a new journey.

insert image description here

1.2. What is the core advantage of DUBBO?

1. Fast and easy to use
Whether you plan to use the microservice architecture to develop a new business system, or prepare to migrate your existing business from a single architecture to a microservice architecture, the Dubbo framework can help you. Dubbo makes microservice development very easy, it allows you to choose multiple programming languages, use any communication protocol, and it also provides a series of development and testing tools for microservice scenarios to help improve R&D efficiency

2. Ultra-high performance
and high-performance data transmission
to build a scalable microservice cluster

3. Service governance
provides:

  1. traffic control
  2. Microservice Ecology
  3. visual console
  4. security system
  5. Service Network

2. Quick start

reference documents

  1. dubbo official document (dubbo*springboot quick start)

2.1.windows start registration center

1. Download and start zookeeper (version 3.7.1)
insert image description here

2. Start the registration center.
insert image description here

2.2. Configure the monitoring center (visual monitoring and management)

  1. Download and compile dubbo-admin
    source address

If the ports are all default, just start it directly (you can start it directly in idea, or use the java -jar command to start springboot, don’t use jdk17 to report an error )
insert image description here

Open? Can't open it! Hahaha, because it is not a finished project, you need to compile and run the front-end Vue project by yourself

Remember to cd to the ui directory. If there is no relevant environment, you can search for vue articles and install the relevant environment of vue3.
2. Install related dependencies

npm i
  1. run project
npm run dev

insert image description here

2.3. Create providers and consumers (springboot creation)

2.3.1. Create interface module

Create a parent project.

  • Follow the instructions on the official website to modify the pom file
    insert image description here
  <properties>
        <dubbo.version>3.2.0-beta.4</dubbo.version>
        <spring-boot.version>2.7.8</spring-boot.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Spring Boot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Dubbo -->
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-bom</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

2.3.1. Create interface module (for exposing interface)

The pom file does not need to be modified in particular.
insert image description here

  • Then expose the interface
    insert image description here
public interface DemoService {
    
    

    String sayHello(String name);
}

2.3.2. Create consumer and provider modules (the same applies to the creation of two projects)

1. Create a module (I misspelled the word provider here,...but it's not a big problem, let's make do with it first)

What needs to be noted here is to change the interface maven dependency address to the address of your own interface module maven
insert image description here

 <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-interface</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
    <dependencies>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-interface</artifactId>
            <version>${project.parent.version}</version>
        </dependency>

        <!-- dubbo -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
            <type>pom</type>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-reload4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- spring boot starter -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

    </dependencies>

2. The server (provider) implements the interface'
insert image description here

@DubboService
public class DemoServiceImpl implements DemoService {
    
    

    @Override
    public String sayHello(String name) {
    
    
        return "Hello " + name;
    }
}

3. Server (provider) configuration link configuration:

  • I configure it here through the yml file.
dubbo:
  application:
    name: dubbo-springboot-demo-provider
  protocol:
    name: dubbo
    port: -1
  registry:
    address: zookeeper://${zookeeper.address:127.0.0.1}:2181

insert image description here

Since my zookeeper is the default value, it can be configured directly like this, and can be set according to your own configuration

insert image description here
@EnableDubboFinally, open the annotation on the startup class

3. Consumer configuration link configuration:

  • configuration yml
    insert image description here
  • Configure consumer request tasks
@Component
public class Task implements CommandLineRunner {
    
    
    @DubboReference
    private DemoService demoService;

    @Override
    public void run(String... args) throws Exception {
    
    
        String result = demoService.sayHello("world");
        System.out.println("Receive result ======> " + result);

        new Thread(()-> {
    
    
            while (true) {
    
    
                try {
    
    
                    Thread.sleep(1000);
                    System.out.println(new Date() + " Receive result ======> " + demoService.sayHello("world"));
                } catch (InterruptedException e) {
    
    
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                }
            }
        }).start();
    }
}

insert image description here
@EnableDubboFinally, open the annotation on the startup class

2.3.3. Start the test

Test success! (QAQ)
insert image description here
insert image description here

However, in the absence of sorting, there are many services that need to be started. Here is a brief summary.

  • Monitoring Center (dubbo-admin)
  • 1. Monitoring center backend serviceinsert image description here
  • 2. Monitoring center front-end service
    insert image description here3. Registration center (Zookeeper)
    insert image description here
    4. Server (provider)
    insert image description here
    5. Consumer
    insert image description here
    There are 5 services in total.

Guess you like

Origin blog.csdn.net/faker1234546/article/details/129767914