乐闻世界logo
搜索文章和话题

What are the core architecture and features of the Dubbo framework? How does Dubbo implement service governance?

2月22日 14:08

Dubbo is a high-performance Java RPC framework open-sourced by Alibaba, widely used in microservice architectures:

Core Architecture:

1. Service Provider

  • Application that exposes services
  • Registers services with the registry at startup
  • Can deploy multiple instances for load balancing

2. Service Consumer

  • Application that calls remote services
  • Subscribes to services from the registry at startup
  • Calls remote services through proxies

3. Registry

  • Core component for service registration and discovery
  • Common implementations: Zookeeper, Nacos, Redis
  • Responsible for maintaining service lists and health status

4. Monitor

  • Statistics on service call counts and call times
  • Provides data support for service governance
  • Common implementations: Dubbo Admin, Prometheus

5. Container

  • Service runtime container
  • Common: Spring Container, Spring Boot

Core Features:

1. Remote Call

  • Supports multiple protocols: Dubbo, RMI, Hessian, HTTP, Webservice, Thrift, REST
  • Default uses Dubbo protocol (based on Netty)
  • Supports both synchronous and asynchronous calls

2. Cluster Fault Tolerance

  • Failover: Automatic failover, default strategy
  • Failfast: Fast failure, only initiates one call
  • Failsafe: Fail-safe, ignores exceptions
  • Failback: Automatic recovery, records failed requests in background
  • Forking: Parallel calls, returns as soon as one succeeds
  • Broadcast: Broadcast call, all calls must succeed

3. Load Balancing

  • Random: Random, sets random probability based on weights
  • RoundRobin: Round robin, sets round robin ratio based on reduced weights
  • LeastActive: Least active call count
  • ConsistentHash: Consistent hash, requests with same parameters always go to same provider

4. Service Degradation

  • Mock data
  • Return null
  • Throw specified exception

5. Service Rate Limiting

  • Concurrency limit
  • QPS limit

6. Service Routing

  • Conditional routing
  • Tag routing
  • Script routing

7. Configuration Center

  • Dynamic configuration
  • Configuration version management
  • Configuration push

Usage Example:

Service Provider:

java
@Service public class UserServiceImpl implements UserService { @Override public User getUserById(Long id) { return new User(id, "Zhang San"); } } // Configuration <dubbo:service interface="com.example.UserService" ref="userService"/>

Service Consumer:

java
// Configuration <dubbo:reference interface="com.example.UserService" id="userService"/> // Usage @Autowired private UserService userService; public void test() { User user = userService.getUserById(1L); }

Advantages:

  • High Performance: Based on Netty, supports long connections
  • Ease of Use: Deep integration with Spring
  • Extensibility: Supports multiple protocols and load balancing strategies
  • Service Governance: Comprehensive service governance features
  • Active Community: Continuously maintained by Alibaba and community

Applicable Scenarios:

  • Java microservice architecture
  • Internal service calls
  • High concurrency scenarios
  • Systems requiring comprehensive service governance
标签:RPC