Article directory
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.
In 2017, Dubbo was officially donated to the Apache Software Foundation and became a top Apache project, starting a new journey.
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:
- traffic control
- Microservice Ecology
- visual console
- security system
- Service Network
2. Quick start
reference documents
2.1.windows start registration center
1. Download and start zookeeper (version 3.7.1)
2. Start the registration center.
2.2. Configure the monitoring center (visual monitoring and management)
- 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 )
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
- run project
npm run dev
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
<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.
- Then expose the interface
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
<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'
@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
Since my zookeeper is the default value, it can be configured directly like this, and can be set according to your own configuration
@EnableDubbo
Finally, open the annotation on the startup class
3. Consumer configuration link configuration:
- configuration yml
- 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();
}
}
@EnableDubbo
Finally, open the annotation on the startup class
2.3.3. Start the test
Test success! (QAQ)
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 service
- 2. Monitoring center front-end service
3. Registration center (Zookeeper)
4. Server (provider)
5. Consumer
There are 5 services in total.