Cloud Native 11 min read

Connect Dubbo and Spring Cloud: Step‑by‑Step Mixed Deployment Guide

This article demonstrates how to achieve low‑cost, code‑minimal integration between Apache Dubbo and Spring Cloud, enabling mixed deployment and migration scenarios by leveraging Dubbo’s built‑in REST support, multi‑protocol publishing, and Nacos registration, with complete sample code and configuration details.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Connect Dubbo and Spring Cloud: Step‑by‑Step Mixed Deployment Guide

Background and Goal

The article shows a practical, code‑first approach to make Apache Dubbo and Spring Cloud microservice ecosystems interoperate with minimal code changes, enabling mixed deployment, migration, and coexistence of the two frameworks.

Target Scenarios

You have an existing Dubbo‑based service and need to expose part of it as a REST HTTP endpoint for Spring Cloud clients without modifying the original code.

You run both Spring Cloud and Dubbo microservice stacks and want each side to call services provided by the other.

You need a smooth, phased migration from one framework to the other.

Dubbo REST Support

Dubbo 3 provides a built‑in REST programming model that works with standard JAX‑RS or Spring MVC annotations, allowing Dubbo to act both as a consumer of HTTP services and as a provider of RESTful endpoints without changing existing business logic.

Example 1: Dubbo Calls Spring Cloud

We start from a Spring Cloud service that registers with Nacos. The service configuration is:

server:
  port: 8099
spring:
  application:
    name: spring-cloud-provider-for-dubbo
  cloud:
    nacos:
      serverAddr: 127.0.0.1:8848 # registration center

A simple controller publishes /users/list:

@RestController
@RequestMapping("/users")
public class UserController {
    @GetMapping("/list")
    public List<User> getUser() {
        return Collections.singletonList(new User(1L, "spring cloud server"));
    }
}

After starting the Spring Cloud application, a Dubbo client can call the service by declaring a Feign‑style interface and annotating it with @DubboReference:

@DubboReference
private UserServiceFeign userService;

Invocation is straightforward: List<User> users = userService.users(); The Dubbo consumer is launched via DubboConsumerApplication and successfully invokes the Spring Cloud endpoint.

Example 2: Spring Cloud Calls Dubbo

We now expose a Dubbo service as a REST endpoint. The Dubbo service interface is annotated with Spring MVC annotations:

@RestController
@RequestMapping("/users")
public interface UserService {
    @GetMapping(value = "/list")
    List<User> getUsers();
}

The implementation is a regular Dubbo service:

@DubboService
public class UserServiceImpl implements UserService {
    @Override
    public List<User> getUsers() {
        return Collections.singletonList(new User(1L, "Dubbo provider!"));
    }
}

Dubbo’s configuration sets the protocol to rest and registers with Nacos:

dubbo:
  registry:
    address: nacos://127.0.0.1:8848
    register-mode: instance
  protocol:
    name: rest
    port: 8090

A Spring Cloud application uses OpenFeign to call the Dubbo‑provided REST service:

@FeignClient(name = "dubbo-provider-for-spring-cloud")
public interface UserServiceFeign {
    @RequestMapping(value = "/users/list", method = RequestMethod.GET)
    List<User> getUsers();
}

Controller for testing:

public class UserController {
    private final RestTemplate restTemplate;
    private final UserServiceFeign userServiceFeign;

    public UserController(RestTemplate restTemplate, UserServiceFeign userServiceFeign) {
        this.restTemplate = restTemplate;
        this.userServiceFeign = userServiceFeign;
    }

    @RequestMapping("/rest/test1")
    public String doRestAliveUsingEurekaAndRibbon() {
        String url = "http://dubbo-provider-for-spring-cloud/users/list";
        System.out.println("url: " + url);
        return restTemplate.getForObject(url, String.class);
    }

    @RequestMapping("/rest/test2")
    public List<User> doRestAliveUsingFeign() {
        return userServiceFeign.getUsers();
    }
}

Accessing http://localhost:8099/rest/test1 or /rest/test2 verifies the call.

Multi‑Protocol Publishing

Dubbo can publish a service on both rest and native dubbo protocols simultaneously, allowing the same service to serve both ecosystems.

dubbo:
  protocols:
    - id: rest
      name: rest
      port: 8090
    - id: dubbo
      name: dubbo
      port: 20880

The service annotation is updated accordingly:

@DubboService(protocol="rest,dubbo")
public class UserServiceImpl implements UserService {}

Now the UserService is reachable via http://localhost:8090/users/list for Spring Cloud clients and via Dubbo’s native protocol for Dubbo clients.

Conclusion

By leveraging Dubbo’s REST programming model, multi‑protocol publishing, and Nacos registration, developers can achieve low‑cost, near‑zero‑code integration between Dubbo and Spring Cloud, facilitating mixed deployments, gradual migrations, and seamless inter‑framework communication. The approach is demonstrated with complete source samples and configuration files, and will be officially supported in Dubbo 3.3.0 with additional Triple protocol enhancements.

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.

JavaNacosSpring Cloudrest
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.