Dubbo Documentation

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

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.

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

provider.xml:

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:

log4j.properties

Bootstrap the service provider

Provider.java

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

consumer.xml:

Bootstrap the consumer

Consumer.java:

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.

最后更新:2019-04-03
weinxin
关于本站
本站是一个分享建站经验、SEO优化、互联网技术以及日常生活的个人生活博客。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: