Basic Introduction

Apache Dubbo is a high-performance Java RPC (Remote Procedure Call) framework. Its predecessor was a high-performance, lightweight distributed service framework open-sourced by Alibaba in 2011. In 2018, Dubbo officially entered the Apache incubator and became an Apache top-level project.

Core features of Dubbo include:

  1. High-performance network communication: Based on Netty for efficient NIO communication
  2. Automatic service registration and discovery: Supports multiple registries such as ZooKeeper, Nacos, etc.
  3. Load balancing: Provides multiple load balancing strategies such as random, round-robin, consistent hashing, etc.
  4. Service fault tolerance: Supports fault tolerance mechanisms such as retry on failure, fail-fast, failover, etc.
  5. Service governance: Provides rich service governance functions such as service degradation, access control, etc.

Service Governance (SOA Governance)

Service governance is a series of management processes implemented by enterprises to ensure the successful completion of SOA (Service-Oriented Architecture) projects, mainly including the following aspects:

  1. Best Practices: Such as service splitting principles, interface design specifications, etc.
  2. Architecture Principles: Such as service loose coupling, service autonomy, etc.
  3. Governance Procedures: Including service lifecycle management, change management, etc.

Core Roles

Provider (Service Provider):

  • Service instance that implements specific business logic
  • Registers the service interface it provides to the registry at startup

Consumer (Service Consumer):

  • Client application that calls remote services
  • Subscribes to required services at startup to obtain the provider address list

Registry:

  • Uses ZooKeeper as the recommended implementation
  • Responsible for service address registration and discovery

Monitor:

  • Collects and counts RPC call metrics

Container (Service Container):

  • Usually uses Spring container
  • Responsible for initializing, managing, and running service instances

Dubbo Getting Started Guide

Configuration Methods Explained

1. Annotation-based Configuration

// Service Provider
@Service(version = "1.0.0")
public class UserServiceImpl implements UserService {}

// Service Consumer
@Reference(version = "1.0.0")
private UserService userService;

2. XML Configuration

<!-- Provider configuration -->
<dubbo:service interface="com.example.UserService" ref="userService" version="1.0.0"/>

<!-- Consumer configuration -->
<dubbo:reference id="userService" interface="com.example.UserService" version="1.0.0"/>

3. Code-based Configuration

// Service provider configuration
ServiceConfig<UserService> service = new ServiceConfig<>();
service.setInterface(UserService.class);
service.setRef(new UserServiceImpl());
service.setVersion("1.0.0");
service.export();

// Service consumer configuration
ReferenceConfig<UserService> reference = new ReferenceConfig<>();
reference.setInterface(UserService.class);
reference.setVersion("1.0.0");
UserService userService = reference.get();

Project Structure Planning

Recommended Maven multi-module project structure:

parent-project
├── api-module        // Interface definition
├── provider-module   // Service implementation
└── consumer-module  // Service invocation