Dubbo Documentation

2018年11月24日02:01:54 评论 511

The most common way to use Dubbo is to run it in Spring framework. The following content will guide you to develop a Dubbo application with Spring framework's XML configuration.

Dubbo Documentation

If you don't want to rely on Spring, you can try using API configuration.

First let's create a root directory called dubbo-demo:

Next, we are going to create 3 sub-directories under root directory:

  • dubbo-demo-api: the common service api
  • dubbo-demo-provider: the demo provider codes
  • dubbo-demo-consumer: the demo consumer codes

Service provider

Defining service interfaces

DemoService.java [1]:

The proejct structure should look like this:

Implement interface in service provider

DemoServiceImpl.java [2]:

Exposing service with Spring configuration


The demo uses multicast as the registry since it is simple and does not require to extra installation. If you prefer a registiry like zookeeper, please check out examples here.

Configure the logging system

Dubbo use log4j as logging system by default, it also support slf4j, Apache Commons Logging, and JUL logging.

Following is a sample configuration:


Bootstrap the service provider


Finally, the project structure should look like this:

Service consumer

Complete installation steps, see:Consumer demo installation

Using the Spring configuration to reference a remote service


Bootstrap the consumer


Config the logging system

This is the same as how to config it on provider side.

Finally, the project structure should be look like this:

Start the demo

Start service provider

Run the org.apache.dubbo.demo.provider.Provider class to start the provider.

Start service consumer

Run the org.apache.dubbo.demo.provider.Consumer class to start the consumer, and you should be able to see the following result:

Complete example

You can find the complete example code in the Github repository.

Java 最后更新:2022年8月8日


匿名网友 填写信息