×
Community Blog Dubbo Initializer: Simplifying Project Initialization and Dependency Management

Dubbo Initializer: Simplifying Project Initialization and Dependency Management

This article explains how to quickly create a Dubbo Spring Boot project using the Dubbo Initializer template.

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.

What is Dubbo Initializer?

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.

Use Dubbo Initializer to Create a Dubbo Spring Boot Microservice Project

Visit https://start.dubbo.apache.org/ and you will see the following interface.

1

Select a Dubbo Version

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.

2

Enter the Basic Information of a Project

Next, enter the basic information of a project, including project coordinate, project name, package name, and JDK version.

3

Select the Project Architecture

There are two available project architectures: single-module and multi-module. In this example, we choose single-module architecture.

4

• 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.

Select Dependencies

By default, we select the following dependencies for the template:

  • Dubbo components

    • Java Interface
    • Registry (Zookeeper)
    • TCP
  • Common microservice components

    • Web
    • Mybatis
    • Template Engine

5

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.

Generate a Project Template

• Click EXPLORE to browse the project structure and code online.
• Click GENERATE to generate the project download address.

6

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.

Interpretation of Sample Project Code

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>

Summary

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:

Official Cooperation with IntelliJ IDEA

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

Dubbo Boot Starters

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 .

0 1 0
Share on

You may also like

Comments