Cloud Native 18 min read

Unlock Seamless Service Governance: Dubbo Spring Cloud Meets Spring Cloud Stack

This article explains how Dubbo Spring Cloud bridges Apache Dubbo 3.0 with the Spring Cloud ecosystem, covering version compatibility, service registration and discovery, load balancing, circuit breaking, service introspection, migration strategies, and provides step‑by‑step Maven and YAML configurations with complete code examples for both provider and consumer applications.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Unlock Seamless Service Governance: Dubbo Spring Cloud Meets Spring Cloud Stack

Background and Motivation

In the Java micro‑service ecosystem Spring Cloud is the dominant stack, but many teams encounter scaling and migration limitations. Dubbo 3.0 introduces application‑level service discovery, enabling tighter integration with cloud‑native infrastructure and providing a low‑cost path for developers to adopt Dubbo while retaining Spring Cloud features.

Version Compatibility

Dubbo Spring Cloud supports Spring Cloud "F" and "G" releases (the deprecated "E" release is not supported). It is built on Dubbo Spring Boot 2.7.x and requires Java 1.8 or higher.

Feature Comparison

Distributed Configuration : Spring Cloud native sources (Git, Zookeeper, Consul, JDBC) plus Dubbo configuration center (available since Dubbo 2.7).

Service Registry & Discovery : Supports Eureka, Zookeeper, Consul and adds Spring Cloud Alibaba Nacos as a native option.

Load Balancing : Uses Dubbo built‑in algorithms (random, round‑robin, weight) instead of Ribbon.

Circuit Breaker : Combines Spring Cloud Hystrix with Alibaba Sentinel.

Service Calls : Extends Spring Cloud Open Feign and @LoadBalanced RestTemplate with Dubbo @Service and @Reference annotations.

Tracing : Supports Zipkin and OpenTracing.

Highlighted Capabilities

Dubbo can use any Spring Cloud registry (Nacos, Eureka, Zookeeper, Consul) by setting dubbo.registry.address = spring-cloud://localhost.

Dubbo services become first‑class citizens in Spring Cloud calls; developers can replace Feign or @LoadBalancedRestTemplate with Dubbo @Reference.

Service introspection reduces registry load by centralising metadata, allowing a cluster to scale without extra infrastructure.

Migration is eased with the @DubboTransported annotation, which lets existing Feign interfaces delegate to Dubbo without changing URLs.

Simple Example – Provider

1. Define a common service interface:

public interface EchoService {
    String echo(String message);
}

2. Create a Maven project spring-cloud-dubbo-server-sample and add the following dependencies:

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dubbo-sample-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-dubbo</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
</dependencies>

3. Implement the service:

@org.apache.dubbo.config.annotation.Service
public class EchoServiceImpl implements EchoService {
    @Override
    public String echo(String message) {
        return "[echo] Hello, " + message;
    }
}

4. Configure Dubbo and Spring Cloud (YAML):

dubbo:
  scan:
    base-packages: org.springframework.cloud.alibaba.dubbo.bootstrap
  protocol:
    name: dubbo
    port: -1
  registry:
    address: spring-cloud://localhost
spring:
  application:
    name: spring-cloud-alibaba-dubbo-server
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

5. Bootstrap the application:

@EnableDiscoveryClient
@EnableAutoConfiguration
public class DubboSpringCloudServerBootstrap {
    public static void main(String[] args) {
        SpringApplication.run(DubboSpringCloudServerBootstrap.class, args);
    }
}

Simple Example – Consumer

1. Create Maven project spring-cloud-dubbo-client-sample with the same dependencies as the provider (add spring-boot-starter-web for a REST endpoint).

2. Configure the consumer (YAML):

dubbo:
  cloud:
    subscribed-services: spring-cloud-alibaba-dubbo-server
spring:
  application:
    name: spring-cloud-alibaba-dubbo-client
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848

3. Bootstrap and expose a REST endpoint that calls the Dubbo service:

@EnableDiscoveryClient
@EnableAutoConfiguration
@RestController
public class DubboSpringCloudClientBootstrap {
    @Reference
    private EchoService echoService;

    @GetMapping("/echo")
    public String echo(String message) {
        return echoService.echo(message);
    }

    public static void main(String[] args) {
        SpringApplication.run(DubboSpringCloudClientBootstrap.class, args);
    }
}

Running the client and invoking curl http://127.0.0.1:8080/echo?message=demo returns [echo] Hello, demo, demonstrating successful cross‑stack service consumption.

Advanced Samples and Modules

The repository includes additional modules such as spring-cloud-dubbo-provider-web-sample, spring-cloud-dubbo-consumer-sample, and a servlet‑gateway example, illustrating non‑web providers, web providers, and gateway integration.

Feedback and Further Reading

Issues can be reported at https://github.com/alibaba/spring-cloud-alibaba/issues. For deeper design details, refer to the Spring Cloud Alibaba wiki (https://github.com/alibaba/spring-cloud-alibaba/wiki) and the Dubbo blog (http://dubbo.apache.org/zh-cn/blog/index.html).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaCloud Nativeservice discoveryDubboSpring Cloud
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.