Cloud Toolkit lets you quickly create a Dubbo project and then deploy it to EDAS. This topic describes how to use Cloud Toolkit in IntelliJ IDEA to create a sample Apache Dubbo project that includes a provider and a consumer. You will also learn how to verify the project by making a local call.
Prerequisites
Make sure that Cloud Toolkit 2019.6.2 or later is installed and configured in IntelliJ IDEA. For more information, see Install and configure Cloud Toolkit in IntelliJ IDEA.
Procedure
- Open IntelliJ IDEA. In the menu bar, choose .
- In the New Project dialog box, click Apache Dubbo in the navigation pane on the left. On the right side of the dialog box, select a JDK version and click Next.
- Set the basic project configurations and click Next.
The following list describes the basic parameters and provides examples:
- Project: Select Maven Project.
- GroupId: Enter a group ID, such as com.dubbo.example.
- ArtifactId: Enter an artifact ID, such as dubbo-demo.
- Version: The version of the application project, such as 1.0-SNAPSHOT.
- Dubbo: The version of Dubbo, such as 2.7.2.
- Type: The project type. Select Consumer and Provider to create a sample project for a service provider and a service consumer.
- Spring Boot: The version of Spring Boot, such as 2.1.5.RELEASE.
- Set Project name and Project location, and then click Finish.
The procedure is as follows:
Verify the Apache Dubbo sample application project
The sample Apache Dubbo project created by Cloud Toolkit is a Spring Boot and Dubbo project. The server-side (provider) provides a service named com.dubbo.example.DemoService. The service is exposed on port 12345 over the Dubbo protocol.
dubbo.registry.address=N/A. This means the service is not registered with any registry. The client (consumer) must discover the service through a direct connection.
Step 1: Start the provider
- In IntelliJ IDEA, run the main function of
com.dubbo.example.provider.DubboProviderBootstrap. - Check the standard output.
If the following output appears, the server-side (provider) has started successfully.
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...
Step 2: Start the consumer and verify the call
The com.dubbo.example.consumer.DubboConsumerBootstrap file on the client (consumer) contains the following code:
@Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
private DemoService demoService;
This code indicates that the client (consumer) calls the service by directly connecting to the server-side (provider) address dubbo://127.0.0.1:12345.
- In IntelliJ IDEA, run the main function of
com.dubbo.example.consumer.DubboConsumerBootstrap. - Check the log output on the server-side (provider). The following output appears:
Hello mercyblitz, request from consumer: /30.5.124.39:59553 - Check the log output on the client (consumer). If the following output appears, the call is successful.
Hello mercyblitz, response from provider: 30.5.124.39:12345
- To use a registry for service registration and discovery, modify the dubbo.registry.address in the dubbo-demo/dubbo-demo-provider/src/main/resources/application.properties and dubbo-demo/dubbo-demo-consumer/src/main/resources/application.properties files. Set the value to the address of your registry, such as zookeeper://localhost:2181.
- If you use ZooKeeper as the registry, you must also add the ZooKeeper dependency to the pom.xml file in both the provider and consumer sample projects.
What to do next
After you create the sample Apache Dubbo project and verify the service call, you can package the project into a JAR file. Then, you can deploy the file to different types of EDAS clusters, such as ECS clusters and container service for Kubernetes clusters.