Alibaba Cloud Toolkit is an integrated development environment (IDE) plug-in for developers. You can use Alibaba Cloud Toolkit to create a sample project for a Dubbo application and deploy the project to Enterprise Distributed Application Service (EDAS) after the project is verified. This topic uses IntelliJ IDEA as an example to describe how to create a sample project for a Dubbo application. This project uses Nacos as a registry.
Before you begin
Before you create an Apache Dubbo sample application using Cloud Toolkit, complete the following tasks:
Install and configure Cloud Toolkit in IntelliJ IDEA.
If you use Eclipse, install and configure Alibaba Cloud Toolkit in Eclipse. For more information, see Install and configure Cloud Toolkit in Eclipse.
If you have installed Alibaba Cloud Toolkit, check whether its version is 2019.6.2 or later. Upgrade Alibaba Cloud Toolkit if its version is earlier than 2019.6.2.
In the IntelliJ IDEA toolbar, click the Cloud Toolkit icon
and select About.In the About Alibaba Cloud Toolkit dialog box, view the version information.
Start Nacos Server locally.
In this topic, the registry of the sample project is Nacos. Start Nacos Server in your on-premises environment before you create the sample project.
Download the latest version of Nacos Server.
Decompress the downloaded Nacos Server package.
Go to the
nacos/binfolder and start Nacos Server.On Linux, Unix, or macOS, run the command
sh startup.sh -m standalone.On Windows, double-click the
startup.cmdfile.
Optional:
When you develop applications locally, you can use the Alibaba Cloud Toolkit plug-in to enable mutual calls between local applications and applications deployed in EDAS, which is called end-to-cloud interconnection. This way, you do not need to set up a VPN and can improve development efficiency. For more information, see Overview of end-to-cloud interconnection.
Create a sample project for a Dubbo application
Start IntelliJ IDEA. In the menu bar, choose File > New > Project.
In the New Project dialog box, click Apache Dubbo in the navigation pane on the left. On the right side of the page, select the JDK that is installed in your on-premises environment and click Next.
Set the parameters of the sample project and click Next.
The application parameters include the Dubbo version, registry, configuration method, and Spring Boot version.
Parameter description and example:
Project: Select Maven Project.
GroupId: Enter the Group ID, such as com.dubbo.example.
ArtifactId: Enter dubbo-demo.
Version: The version of the application, such as 1.0-SNAPSHOT.
Dubbo: From the drop-down list, select the Dubbo version, such as 2.7.3.
Registry: Select Nacos.
Configuration Method: Specifies the development method for the sample project. Annotation is the recommended method.
Type: Select the Consumer and Provider check boxes to create a demo application that contains a service provider and a service consumer.
Spring Boot: The Spring Boot version, such as 2.1.5.RELEASE.
Set Project name and Project location, and click Finish.
After the application is created, the Apache Dubbo sample application is displayed in IntelliJ IDEA. This sample application contains a provider, a consumer, and a service interface.
Verify the sample project
You must verify the demo code and configuration because the sample project uses Nacos as the registry and uses annotations for development. You must also verify whether service calls are successful because a provider and a consumer are created.
This sample application is a Spring Boot and Dubbo project. Verify that the
pom.xmlfile contains the Apache Dubbo dependency.<dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> </dependency>The sample application uses Nacos as the registry. Verify that the
pom.xmlfile contains the Nacos Registry dependency.<dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-registry-nacos</artifactId> <version>${dubbo.version}</version> </dependency>Also, verify the configuration of the local Nacos Server in the
application.propertiesfile.## Dubbo Registry dubbo.registry.address=nacos://localhost:8848The sample application consists of a provider and a consumer.
The provider offers a service,
com.dubbo.example.DemoService, which is exposed on port12345over the Dubbo protocol. The configuration is specified inapplication.properties.# Dubbo Protocol dubbo.protocol.name=dubbo dubbo.protocol.port=12345The consumer calls the provider's service via Nacos Server.
@Reference(version = "1.0.0") private DemoService demoService;
Verify service calls
Start the provider.
In IntelliJ IDEA, run the
mainfunction ofcom.dubbo.example.provider.DubboProviderBootstrap.Observe the standard output.
The provider is started if the following information appears:
2019-07-03 16:05:50.585 INFO 19246 --- [ main] c.d.e.provider.DubboProviderBootstrap : Started DubboProviderBootstrap in 36.512 seconds (JVM running for 42.004) 2019-07-03 16:05:50.587 INFO 19246 --- [pool-1-thread-1] .b.c.e.AwaitingNonWebApplicationListener : [Dubbo] Current Spring Boot Application is await...
Start the consumer and verify the call.
In IntelliJ IDEA, run the
mainfunction ofcom.dubbo.example.consumer.DubboConsumerBootstrap.Observe the log output on the server-side (provider). If the following information is displayed, the call is successful.
Hello Provider, response from provider: 30.5.XXX.XXX:12345
Deploy the sample project
After you create and verify the sample project for a Dubbo application, you can use Alibaba Cloud Toolkit to package the sample project as a JAR package and deploy the project to different clusters in EDAS as needed.