All Products
Search
Document Center

Microservices Engine:Build a service registry for Dubbo applications on MSE

Last Updated:Aug 25, 2026

In this tutorial, you build a service registry on Microservices Engine (MSE) for an Apache Dubbo application and use it for service registration and discovery. By the end, a Dubbo consumer that runs on your local machine calls a provider that it discovers through an MSE Nacos registry.

Architecture

The example application is a Dubbo microservice application that consists of a provider and a consumer. You develop the two roles as two separate Maven projects on your local machine, and both connect to the same registry instance on MSE over its public endpoint.

  • Provider project — Exposes the com.alibaba.mse.IHelloService interface as a Dubbo service on port 28082 and registers the service with the registry instance on MSE.

  • Consumer project — Subscribes to com.alibaba.mse.IHelloService through the same registry instance and calls the provider.

  • Registry instance on MSE — Acts as the service registry that the provider registers with and the consumer subscribes to.

Registry types

MSE can host a Nacos, ZooKeeper, or Eureka service registry for a Dubbo application. This tutorial uses MSE Nacos, and every configuration example in this topic targets an MSE Nacos instance.

  • Nacos (used in this tutorial) — Set the Dubbo registry address to the public endpoint of your MSE Nacos instance. No other registry-specific configuration is required.

  • ZooKeeper — If you use MSE ZooKeeper as your service registry, replace the registry code in Step 2 with the corresponding code for ZooKeeper. For more information, see Usage notes.

Prerequisites

  • Download Maven and set the environment variables.

  • An IDE, such as IntelliJ IDEA or Eclipse, is installed on your local machine.

  • An MSE Nacos instance. For instructions, see Create a Nacos engine instance

  • Create a namespace. This tutorial uses the default namespace, Public.

Step 1: Create the provider project and define the service

In this step, you create the Maven project for the provider and define the service that the provider exposes. In Dubbo, all services are provided as interfaces.

  1. In your IDE, create a Maven project for the provider.

  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>
  3. In the src/main/java directory, create a package named com.alibaba.mse.

  4. In com.alibaba.mse, create an interface named IHelloService that contains a sayHello method.

    package com.alibaba.mse;
    
    public interface IHelloService {
        String sayHello(String str);
    }
  5. In com.alibaba.mse, create a class named IHelloServiceImpl that implements the interface.

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

Step 2: Configure the provider to use MSE Nacos as the registry

In this step, you create the provider.xml file, which exposes IHelloService as a Dubbo service and points the provider at the MSE Nacos instance. Get the endpoint of the instance first, because the registry configuration requires it.

  1. Log on to the MSE console and view the public endpoint of the Nacos instance that you created on MSE. The public endpoint is shown in the Access Method column of the instance list and is in the mse.XX.nacos.mse.aliyuncs.com format.

  2. In the src/main/resources directory of the provider project, create a file named provider.xml.

  3. Add the following configuration to provider.xml. Replace mse.XX.nacos.mse.aliyuncs.com with the public endpoint of your Nacos instance.

    <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">
    
        <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"/>
    
        <dubbo:registry address="nacos://mse.XX.nacos.mse.aliyuncs.com:8848" />
    </beans>

The following table describes the configuration in provider.xml.

ElementDescription
xmlns, xmlns:xsi, xmlns:dubbo, and xsi:schemaLocationDeclares the Spring XML Namespace (xmlns) and XML Schema Instance (xmlns:xsi), and the Dubbo Namespace (xmlns:dubbo) and Schema Instance (xsi:schemaLocation).
dubbo:applicationThe name of the provider application. This example uses demo-provider.
dubbo:protocolPublishes the service over the dubbo protocol on port 28082.
dubbo:service and beanExpose the IHelloService interface and the IHelloServiceImpl implementation class as a Dubbo service.
dubbo:registrySpecifies the Nacos instance that you created on MSE as the service registry. The address is the public endpoint of the instance.

Step 3: Allow the provider to access the MSE instance

The provider reaches the registry over the public endpoint of the MSE instance, so the whitelist of the instance must permit the traffic. Complete this step before you start the provider. Otherwise, registration fails.

  1. In the MSE console, in the left-side navigation pane, choose Microservices Registry > Instances. On the Instances page, click the MSE instance that you created.

  2. Clear the whitelist of the instance. If you do not specify any IP address or mask, all addresses can access the instance. This tutorial uses an empty whitelist as an example. For more information, see Set a whitelist.

Warning

An empty whitelist allows all addresses to access the MSE instance.

Step 4: Start the provider and verify the registration

In this step, you start the provider and confirm in the MSE console that the service is registered with the Nacos instance.

  1. In com.alibaba.mse, create a class named Provider. Use the following code to load the Spring context in the main method of Provider and expose the Dubbo service that you configured.

    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 Provider to start the service. Keep the process running until you finish the tutorial, because the consumer calls this process.

  3. In the MSE console, on the details page of your MSE instance, choose Service Management > Services in the left-side navigation pane.

  4. Verify that the service list contains com.alibaba.mse.IHelloService, the interface that the demo-provider application exposes.

Do not continue to the next step until the interface appears in the service list. If the interface does not appear, check the following configurations:

  • Whitelist — The whitelist of the MSE instance permits the address of your local machine. An empty whitelist permits all addresses.

  • Registry address — The dubbo:registry address in provider.xml uses the public endpoint of your instance, not the mse.XX.nacos.mse.aliyuncs.com placeholder.

  • Registry type — The dubbo:registry address uses the scheme of the instance type that you created, such as nacos:// for an MSE Nacos instance.

Step 5: Create the consumer and subscribe to the service

In this step, you create a second Maven project for the consumer, subscribe to com.alibaba.mse.IHelloService through the same MSE Nacos instance, and implement the class that calls the provider.

  1. In your IDE, create a second Maven project for the consumer.

  2. Add the dubbo and nacos-client dependencies to the pom.xml file of the consumer project. The dependencies are identical to those of the provider project in Step 1.

  3. In the src/main/java directory, create the com.alibaba.mse package and add the IHelloService interface that you defined in Step 1. The consumer references the service by its interface, so the interface must be on the classpath of the consumer project.

  4. In the src/main/resources directory of the consumer project, create a file named consumer.xml. Replace mse.XX.nacos.mse.aliyuncs.com with the public endpoint of your Nacos instance, which is the same endpoint that you configured in provider.xml.

    <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">
    
        <dubbo:application name="demo-consumer"/>
    
        <dubbo:registry address="nacos://mse.XX.nacos.mse.aliyuncs.com:8848" />
    
        <dubbo:reference id="helloService" interface="com.alibaba.mse.IHelloService"/>
    </beans>

    The dubbo:registry element points the consumer at the same registry as the provider, and the dubbo:reference element subscribes to the com.alibaba.mse.IHelloService interface that the provider exposes.

  5. In com.alibaba.mse, create a class named Consumer. Use the following code to load the Spring context in the main method of Consumer and call the sayHello method of the subscribed service.

    package com.alibaba.mse;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class Consumer {
        public static void main(String[] args) throws Exception {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"consumer.xml"});
            context.start();
            IHelloService helloService = (IHelloService) context.getBean("helloService");
            System.out.println(helloService.sayHello("mse"));
        }
    }

Step 6: Verify the call from the consumer to the provider

In this step, you confirm that the consumer discovers the provider through the MSE Nacos registry and receives the response of the sayHello method. The consumer passes mse as the argument, and IHelloServiceImpl returns hello followed by that argument.

  1. Confirm that the provider process that you started in Step 4 is still running.

  2. Run the main method of Consumer.

  3. Check the console output of the consumer project. The following output indicates that the consumer called the provider successfully:

    hello mse

If the call fails or no output is returned, check the following configurations:

  • Provider availability — The provider process is running, and com.alibaba.mse.IHelloService appears in the service list of the MSE instance.

  • Registry address — The dubbo:registry address in consumer.xml is the public endpoint that you configured in provider.xml.

  • Interface name — The interface in the dubbo:reference element of consumer.xml matches com.alibaba.mse.IHelloService, which is the interface in the dubbo:service element of provider.xml.

  • Whitelist — The whitelist of the MSE instance permits the address of your local machine.