By Dubbo Community
In this article, you'll learn how to quickly create a Dubbo Spring Boot project using the Dubbo Initializer template to help you solve the problem of project initialization.
Dubbo Initializer is a UI tool that helps developers quickly generate Dubbo Spring Boot projects. It generates project source code with basic Dubbo configuration, code samples, Web, SQL, and other microservice components, and provides methods to download the ZIP package. After downloading the Dubbo Initializer, you can import the project template code into your IDE and add your business logic, eliminating the tedious operations of project initialization.
To create a Spring Boot project with Dubbo Initializer, visit the following link: https://start.dubbo.apache.org/
Note: Dubbo Initializer is still being updated, with more support for Dubbo features to be released soon.
Visit https://start.dubbo.apache.org/ and you will see the following interface.
Dubbo Initializer uses dubbo-spring-boot-starter to create a Spring Boot project. Therefore, we must first select the version of Dubbo and Spring Boot.
Next, enter the basic information of a project, including project coordinate, project name, package name, and JDK version.
There are two available project architectures: single-module and multi-module. In this example, we choose single-module architecture.
• For single-module architecture, all component code is stored in one module, which has a simple structure.
• For multi-module architecture, the generated project includes two modules: API and Service. The API module stores Dubbo service definitions, and the Service module stores service implementation or call logic. Generally, multi-module architecture is more conducive to separate management and release of service definitions.
By default, we select the following dependencies for the template:
Dubbo components
Common microservice components
Based on the options above, the generated project uses Zookeeper as the registry, high-performance Dubbo2 TCP as the RPC communication protocol, and includes component dependencies and examples such as Web and Mybatis.
Note: The Dubbo components selected above are the default options, which means that if you click Generate directly after opening the page without adding any dependencies manually, the generated code will contain the above Dubbo components.
If you manually add dependencies, pay attention to the implicit combination restrictions between Dubbo dependencies:
• If you select Dubbo Service API-IDL, only HTTP/2 or gRPC in Dubbo Protocol is supported.
In a dependency group, you can only select one dependency of the same type. For example, in the Dubbo Registry & Config & Metadata group, you can only select one from Zookeeper and Nacos as the registry. If you want to configure multiple registries, manually modify the configurations in the generated code. However, you can select a registry and a configuration center respectively. For example, Zookeeper and Apollo can be selected simultaneously.
• Click EXPLORE to browse the project structure and code online.
• Click GENERATE to generate the project download address.
After you download the ZIP package to your on-premises machine, decompress the package and import it to the IDE to develop custom Dubbo applications.
The following uses the generated single-module code as an example to explain the meaning of the generated code.
1. Service definition
public interface DemoService { String hello(String arg);}
2. Business logic implementation
@DubboService
public class DemoServiceImpl implements DemoService {
public String hello(String arg) {
// put your microservice logic here
}
}
3. Project configuration
dubbo:
application:
name: dubbo-demo
protocol:
name: dubbo
port: -1
registry:
address: zookeeper://127.0.0.1:2181
4. Code dependencies
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
As an important plan to improve the usability of Dubbo, Dubbo Initializer is still evolving. Here are some of the work being done.
As an important initiative to improve the usability of Dubbo, Dubbo Initializer is still evolving. Here are some of the current developments:
IntelliJ IDEA 2023 has recently released the official framework to support Dubbo.
Apache Dubbo in Spring Framework: https://plugins.jetbrains.com/plugin/20938-apache-dubbo-in-spring-framework
Besides Dubbo Initializer, the Dubbo community is also developing Dubbo Boot Starters. The aim is to allow users to use the Dubbo framework without any configuration. You only need to introduce the Starter dependency, without worrying about the POM dependencies and default configuration being cumbersome.
Click here to try .
Dubbo 3.2: New Features and Enhancements for Cloud Nativeization
Kruise Rollout v0.3.0: How to Master Deployment Batch Release and Traffic Grayscale
503 posts | 48 followers
FollowAlibaba Cloud Native Community - December 19, 2023
Alibaba Cloud Native Community - January 26, 2024
Alibaba Cloud Native Community - July 20, 2023
Alibaba Cloud Native Community - September 13, 2023
Alibaba Cloud Blockchain Service Team - October 25, 2018
Alibaba Cloud Serverless - March 19, 2019
503 posts | 48 followers
FollowGain an industrial edge with Alibaba Cloud best practices
Learn MoreMore Posts by Alibaba Cloud Native Community