All Products
Search
Document Center

Microservices Engine:Register Dubbo microservice applications with an MSE Nacos instance

Last Updated:Mar 11, 2026

Microservices Engine (MSE) provides managed service registries based on Nacos, ZooKeeper, or Eureka. This guide walks you through registering a Dubbo provider and consumer with an MSE Nacos instance so that the consumer can discover and call the provider.

How it works

  1. A Dubbo provider starts and registers its service interface with the Nacos instance on MSE.

  2. A Dubbo consumer subscribes to the same Nacos instance to discover available providers.

  3. The consumer invokes the provider through the Dubbo RPC protocol using the service interface.

Prerequisites

Before you begin, make sure that you have:

This guide uses the default Public namespace.

Set up the provider

Create a Dubbo provider that exposes a service interface and registers it with the MSE Nacos instance.

Step 1: Create a Maven project and add dependencies

  1. Create a Maven project in your IDE (IntelliJ IDEA, Eclipse, or similar).

  2. Add the dubbo and nacos-client dependencies to the pom.xml file:

        <dependencies>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo</artifactId>
                <version>2.7.9</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
                <version>1.4.2</version>
            </dependency>
        </dependencies>

Step 2: Define and implement the service interface

Dubbo services are exposed as Java interfaces. Define the interface first, then provide an implementation.

  1. Create a package named com.alibaba.mse in the src/main/java directory.

  2. In the com.alibaba.mse package, create the IHelloService interface with a sayHello method:

        package com.alibaba.mse;
    
        public interface IHelloService {
           String sayHello(String str);
        }
  3. Create the IHelloServiceImpl class in the same package to implement the interface:

        package com.alibaba.mse;
    
        public class IHelloServiceImpl implements IHelloService {
        public String sayHello(String str) {
            return "hello " + str;
            }
        }

Step 3: Configure the Dubbo service

  1. Create a provider.xml file in the src/main/resources directory.

  2. Add the Spring and Dubbo XML namespace declarations:

        <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
  3. Expose the interface as a Dubbo service and point the registry to your MSE Nacos instance: Replace mse.XX.nacos.mse.aliyuncs.com with the actual endpoint of your MSE Nacos instance. Find this endpoint in the Access Method column on the instance list page of the MSE console.

    Note

    To use the public endpoint, configure an empty whitelist first. For details, see Configure a public IP address whitelist.

    Note

    If your service registry is an MSE ZooKeeper instance, replace the registry address accordingly. For details, see Usage notes.

        <dubbo:application name="demo-provider"/>
    
        <dubbo:protocol name="dubbo" port="28082"/>
    
        <dubbo:service interface="com.alibaba.mse.IHelloService" ref="helloService"/>
    
        <bean id="helloService" class="com.alibaba.mse.IHelloServiceImpl"/>
    
        <!-- Replace mse.XX.nacos.mse.aliyuncs.com with your Nacos instance endpoint -->
        <dubbo:registry address="nacos://mse.XX.nacos.mse.aliyuncs.com:8848" />

Step 4: Start the provider

  1. Create a Provider class in the com.alibaba.mse package. This class loads the Spring context and starts the Dubbo service:

        package com.alibaba.mse;
    
        import org.springframework.context.support.ClassPathXmlApplicationContext;
    
        public class Provider {
            public static void main(String[] args) throws Exception {
                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"});
                context.start();
                System.in.read();
            }
        }
  2. Run the main method of the Provider class to start the service.

Verify provider registration

  1. Log on to the MSE console.

  2. In the left-side navigation pane, choose Microservices Registry > Instances, then click the target MSE instance.

  3. Configure a whitelist for the instance. If no IP addresses or CIDR blocks are added to the whitelist, all IP addresses are allowed to access the instance.

  4. In the left-side navigation pane of the instance details page, choose Service Management > Services. If the provider service appears in the list, the registration succeeded.

Set up the consumer

Create a Spring Boot consumer application that subscribes to the Dubbo service through the same MSE Nacos instance.

Step 1: Create a Maven project and add dependencies

  1. Create a Maven project named spring-boot-dubbo-consumer in your IDE.

  2. Add the dubbo and nacos-client dependencies to the pom.xml file:

        <dependencies>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo</artifactId>
                <version>2.7.9</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
                <version>1.4.2</version>
            </dependency>
        </dependencies>

Step 2: Define the service interface

  1. Create a package named com.alibaba.mse in the src/main/java directory.

  2. Create the same IHelloService interface used by the provider:

        package com.alibaba.mse;
    
        public interface IHelloService {
            String sayHello(String str);
        }

Step 3: Create a controller to call the provider

  1. Create a DemoConsumerController class in the com.alibaba.mse package. Use the @Reference annotation to inject the remote Dubbo service:

    Note

    The @Reference annotation is com.alibaba.dubbo.config.annotation.Reference.

        package com.alibaba.mse;
    
        import com.alibaba.dubbo.config.annotation.Reference;
        import org.springframework.web.bind.annotation.PathVariable;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RestController;
    
        @RestController
        public class DemoConsumerController {
            @Reference
            private IHelloService demoService;
    
            @RequestMapping("/sayHello/{name}")
            public String sayHello(@PathVariable String name) {
                return demoService.sayHello(name);
            }
        }

Step 4: Configure the registry address

Add the following properties to the application.properties file:

server.port=8080
dubbo.application.name=dubbo-consumer-demo
dubbo.registry.address=nacos://mse.XX.nacos.mse.aliyuncs.com:8848

Replace mse.XX.nacos.mse.aliyuncs.com with your MSE Nacos instance endpoint.

Note

The dubbo.registry.address value must start with nacos://, followed by the endpoint and port of the MSE Nacos instance.

Step 5: Start the consumer

  1. Create the Spring Boot entry class SpringBootDubboConsumerApplication and start the application:

        package com.alibaba.mse;
    
        import org.springframework.boot.SpringApplication;
        import org.springframework.boot.autoconfigure.SpringBootApplication;
    
        @SpringBootApplication
        public class SpringBootDubboConsumerApplication {
    
            public static void main(String[] args) {
                SpringApplication.run(SpringBootDubboConsumerApplication.class, args);
            }
        }

Verify consumer registration

  1. Log on to the MSE console.

  2. In the left-side navigation pane, choose Microservices Registry > Instances, then click the target MSE instance.

  3. Configure a whitelist for the instance. If no IP addresses or CIDR blocks are added to the whitelist, all IP addresses are allowed to access the instance.

  4. In the left-side navigation pane of the instance details page, choose Service Management > Services. If the consumer service appears in the list, the registration succeeded.

Verify end-to-end service invocation

With both the provider and consumer running, test that the consumer can call the provider.

Run the following command:

curl http://localhost:8080/sayHello/mse

Expected output:

Hello, mse

This response confirms that the consumer discovered and called the provider through the MSE Nacos service registry.

References