All Products
Search
Document Center

Serverless App Engine:Host Dubbo applications on SAE

Last Updated:Aug 13, 2025

This topic describes how to develop a sample Dubbo microservice application locally using XML configurations and then deploy the application to Serverless App Engine (SAE). The example application contains a service provider (Provider) and a service consumer (Consumer).

Preparations

  • Download Maven and set the environment variables.

  • Start Nacos Server.

    1. Download and decompress the Nacos Server package.

    2. Go to the nacos/bin directory and start Nacos Server.

      • Linux, Unix, or macOS: Run the sudo sh startup.sh -m standalone command.

      • Windows: Run the startup.cmd -m standalone command.

      Note

      standalone indicates that the startup.cmd file is run in standalone mode, not cluster mode. By default, the startup.cmd file is started in cluster mode. If you double-click the startup.cmd file to run the file in a Windows system, the startup fails. In this case, you must configure MODE="standalone" in the startup.cmd file. For more information, see Quick Start for Nacos.

Version guide

The lifecycles of Dubbo 2.7.x and Dubbo 3.0.x ended in March 2023. We recommend that you use a later version to develop your applications. This topic uses Dubbo 3.2.15 as an example to describe how to host Dubbo applications on SAE.

Step 1: Create a provider

Create a provider application project in your local environment, add dependencies, configure service registration and discovery, and specify Nacos as the service registry.

  1. Create a Maven project and add dependencies.

    1. Use an IDE such as IntelliJ IDEA or Eclipse to create a Maven project.

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

      <dependencies>
      
          <dependency>
              <groupId>org.apache.dubbo</groupId>
              <artifactId>dubbo</artifactId>
              <version>3.2.15</version>
          </dependency>
      
          <dependency>
              <groupId>org.apache.dubbo</groupId>
              <artifactId>dubbo-registry-nacos</artifactId>
              <version>3.2.15</version>
          </dependency>
      
          <dependency>
              <groupId>com.alibaba.nacos</groupId>
              <artifactId>nacos-client</artifactId>
              <version>1.1.1</version>
          </dependency>
      </dependencies>            
  2. Develop a Dubbo service provider.

    All Dubbo services are provided through interfaces.

    1. In the src/main/java path, create a package com.alibaba.edas.

    2. In com.alibaba.edas, create an interface IHelloService that contains a sayHello method.

        package com.alibaba.edas;
      
        public interface IHelloService {
            String sayHello(String str);
        }                                
    3. In com.alibaba.edas, create a class IHelloServiceImpl that implements this interface.

        package com.alibaba.edas;
      
        public class IHelloServiceImpl implements IHelloService {
            public String sayHello(String str) {
                return "hello " + str;
            }
        }                          
  3. Configure the Dubbo service.

    1. In the src/main/resources path, create and open the provider.xml file.

    2. In the provider.xml file, add the XML Namespace (xmlns) and XML Schema Instance (xmlns:xsi) for Spring, and the Namespace (xmlns:dubbo) and Schema Instance (xsi:schemaLocation) for Dubbo.

      <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. In the provider.xml file, expose the interface and implementation class as a Dubbo service.

        <dubbo:application name="demo-provider"/>
      
        <dubbo:protocol name="dubbo" port="28082"/>
      
        <dubbo:service interface="com.alibaba.edas.IHelloService" ref="helloService"/>
      
        <bean id="helloService" class="com.alibaba.edas.IHelloServiceImpl"/>                                
    4. In the provider.xml file, specify the local Nacos Server as the service registry.

      <dubbo:registry address="nacos://127.0.0.1:8848" />                                
      • 127.0.0.1 is the address of the Nacos Server. If your Nacos Server is deployed on another server, you must change this value to the IP address of that server. After you deploy the application to SAE, you do not need to make any changes. The service registry address is automatically replaced with the address of the service registry on SAE.

      • 8848 is the port for the Nacos Server and cannot be modified.

  4. Start the service.

    1. In the com.alibaba.edas package, create the Provider class. In its main function, use the following code to load the Spring Context and expose the configured Dubbo service.

      package com.alibaba.edas;
      
      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 function of the Provider to start the service.

  5. Log on to the Nacos console at http://127.0.0.1:8848. In the navigation pane on the left, click Service List to view the provider list.

    The service provider list contains com.alibaba.edas.IHelloService. You can also query the Service Group and Provider IP of the service.

Step 2: Create a consumer

Create a consumer application project in your local environment, add dependencies, and configure the service subscription.

  1. Create a Maven project and add dependencies.

    1. Use an IDE such as IntelliJ IDEA or Eclipse to create a Maven project.

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

      <dependencies>
      
          <dependency>
              <groupId>org.apache.dubbo</groupId>
              <artifactId>dubbo</artifactId>
              <version>3.2.15</version>
          </dependency>
      
          <dependency>
              <groupId>org.apache.dubbo</groupId>
              <artifactId>dubbo-registry-nacos</artifactId>
              <version>3.2.15</version>
          </dependency>
      
          <dependency>
              <groupId>com.alibaba.nacos</groupId>
              <artifactId>nacos-client</artifactId>
              <version>1.1.1</version>
          </dependency>
      </dependencies>            
  2. Develop a Dubbo service consumer.

    All Dubbo services are provided through interfaces.

    1. In the src/main/java path, create a package named com.alibaba.edas.

    2. In the com.alibaba.edas package, create an interface IHelloService that contains a sayHello method.

      Note

      In most cases, an interface is defined in an independent module. The provider and consumer then reference the same module using Maven dependencies. In this topic, two identical interfaces are created for the provider and consumer. However, this method is not recommended for production scenarios.

        package com.alibaba.edas;
      
        public interface IHelloService {
            String sayHello(String str);
        }                                
  3. Configure the Dubbo service.

    1. In the src/main/resources path, create and open a consumer.xml file.

    2. In the consumer.xml file, add the XML Namespace (xmlns) and XML Schema Instance (xmlns:xsi) for Spring, and the Namespace (xmlns:dubbo) and Schema Instance (xsi:schemaLocation) for Dubbo.

      <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. Add the following configuration to the consumer.xml file to subscribe to the Dubbo service.

        <dubbo:application name="demo-consumer"/>
      
        <dubbo:registry address="nacos://127.0.0.1:8848"/>
      
        <dubbo:reference id="helloService" interface="com.alibaba.edas.IHelloService"/>
  4. Start and verify the service.

    1. In the com.alibaba.edas package, create the `Consumer` class. In its `main` function, use the following code to load the Spring Context and to subscribe to and consume the Dubbo service.

          package com.alibaba.edas;
      
          import org.springframework.context.support.ClassPathXmlApplicationContext;
      
          import java.util.concurrent.TimeUnit;
      
          public class Consumer {
              public static void main(String[] args) throws Exception {
                  ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"consumer.xml"});
                  context.start();
                  while (true) {
                      try {
                          TimeUnit.SECONDS.sleep(5);
                          IHelloService demoService = (IHelloService)context.getBean("helloService");
                          String result = demoService.sayHello("world");
                          System.out.println(result);
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
              }
          }               
    2. Run the main function of the Consumer to start the service.

  5. Verify the results.

    After startup, the console continuously prints hello world, which indicates that the service is successfully consumed.

    Log on to the Nacos console at http://127.0.0.1:8848 and click Services in the navigation pane on the left. On the Services page, select Callers.

    The service com.alibaba.edas.IHelloService is displayed. You can also view its Service Group and Subscriber IP.

Step 3: Deploy to SAE

  1. Add the following configuration to the pom.xml files of both the provider and the consumer. Then, run the mvn clean package command to compile the local project into an executable JAR package.

    • Provider

      <build>
       <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <executions>
                     <execution>
                         <goals>
                             <goal>repackage</goal>
                         </goals>
                         <configuration>
                             <classifier>spring-boot</classifier>
                             <mainClass>com.alibaba.sae.Provider</mainClass>
                         </configuration>
                     </execution>
                 </executions>
             </plugin>
       </plugins>
      </build>                             
    • Consumer

      <build>
       <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <executions>
                     <execution>
                         <goals>
                             <goal>repackage</goal>
                         </goals>
                         <configuration>
                             <classifier>spring-boot</classifier>
                             <mainClass>com.alibaba.sae.Consumer</mainClass>
                         </configuration>
                     </execution>
                 </executions>
             </plugin>
       </plugins>
      </build>                        
  2. Deploy the compiled provider and consumer application packages to SAE. For more information, see Deploy a Java application.