Spring Boot 集成 Dubbo

Dubbo 是阿里巴巴開源的基于 Java 的高性能 RPC 框架喉脖,本文介紹 Spring Boot 集成 Dubbo 的開發(fā)過程,更多有關(guān) Dubbo 的技術(shù)細(xì)節(jié)參考 Dubbo 開發(fā)

首先磁餐,使用 IntelliJ IDEA 創(chuàng)建一個包含 3 個 Module 的工程,參考:
IntelliJ IDEA 創(chuàng)建多 Module 工程


demo-spring-boot-dubbo-api 是 Maven 工程阿弃,定義 Dubbo RPC 服務(wù)接口诊霹、服務(wù)模型和服務(wù)異常羞延,通常打包成 jar 被 Dubbo 服務(wù)提供方和消費方依賴。
demo-spring-boot-dubbo-provider 是 Spring Boot 工程畅哑,Dubbo 服務(wù)提供方肴楷。
demo-spring-boot-dubbo-consumer 是 Spring Boot 工程,Dubbo 服務(wù)消費方荠呐。

如何使用 IntelliJ IDEA 創(chuàng)建 Maven 和 Spring Boot 工程請參考:
IntelliJ IDEA 創(chuàng)建 Maven 工程
IntelliJ IDEA 創(chuàng)建 Spring Boot 工程

下面分別介紹這三個工程赛蔫。

1 demo-spring-boot-dubbo-api

1.1 POM 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>demo.spring.boot.dubbo</groupId>
    <artifactId>demo-spring-boot-dubbo-api</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
</project>

1.2 定義接口

package demo.spring.boot.dubbo.api;

public interface GreetingService {

    String welcome(String name);
}

2 demo-spring-boot-dubbo-provider

2.1 POM 文件,注意添加 dubbo-spring-boot-starter 依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>demo.spring.boot.dubbo</groupId>
    <artifactId>demo-spring-boot-dubbo-provider</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo-spring-boot-dubbo-provider</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>0.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

2.2 在配置文件 application.properties 中添加 Dubbo 配置信息泥张,注意:此處只能用 .properties 格式配置文件呵恢,不能使用 .yml 格式配置文件,否則無法成功注冊服務(wù)(暫時還沒追查具體原因)

spring.application.name=demo-spring-boot-dubbo-provider
spring.application.version=1.0

# 基于此包掃描生成 Dubbo 控件
dubbo.scan.basePackages=demo.spring.boot.dubbo.provider.service

dubbo.application.id=demo-spring-boot-dubbo-provider
dubbo.application.name=demo-spring-boot-dubbo-provider

dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880

dubbo.registry.id=demo-multicast-registry
dubbo.registry.address=multicast://224.5.6.7:1234

2.3 定義 Dubbo RPC 服務(wù)接口實現(xiàn)類

package demo.spring.boot.dubbo.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import demo.spring.boot.dubbo.api.GreetingService;

import java.time.LocalDateTime;

@Service(version = "${spring.application.version}",
    application = "${dubbo.application.id}",
    protocol = "${dubbo.protocol.id}",
    registry = "${dubbo.registry.id}")
public class GreetingServiceImpl implements GreetingService {
    
    @Override
    public String welcome(String name) {
        String msg = "Welcome " + name + " at " + LocalDateTime.now();
        System.out.println(msg);
        return msg;
    }
}

2.4 不需要修改自動生成的應(yīng)用啟動類

package demo.spring.boot.dubbo.provider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoSpringBootDubboProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoSpringBootDubboProviderApplication.class, args);
    }
}

啟動應(yīng)用媚创,日志如下渗钉,從 MulticastRegistry 相關(guān)日志信息中可以看見服務(wù)已注冊成功。

C:\Dev\Java\jdk1.8.0_172\bin\java.exe "-javaagent:C:\Dev\JetBrains\IntelliJ IDEA 2018.1.2\lib\idea_rt.jar=50691:C:\Dev\JetBrains\IntelliJ IDEA 2018.1.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Dev\Java\jdk1.8.0_172\jre\lib\charsets.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\deploy.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\access-bridge-64.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\cldrdata.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\dnsns.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\jaccess.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\jfxrt.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\localedata.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\nashorn.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunec.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunjce_provider.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunmscapi.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunpkcs11.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\zipfs.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\javaws.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jce.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jfr.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jfxswt.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jsse.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\management-agent.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\plugin.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\resources.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\rt.jar;D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-provider\target\classes;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot-starter\2.0.4.RELEASE\spring-boot-starter-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot\2.0.4.RELEASE\spring-boot-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-context\5.0.8.RELEASE\spring-context-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-aop\5.0.8.RELEASE\spring-aop-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-beans\5.0.8.RELEASE\spring-beans-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-expression\5.0.8.RELEASE\spring-expression-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot-autoconfigure\2.0.4.RELEASE\spring-boot-autoconfigure-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot-starter-logging\2.0.4.RELEASE\spring-boot-starter-logging-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\JYL\DEV\Maven\repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\JYL\DEV\Maven\repo\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;D:\JYL\DEV\Maven\repo\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;D:\JYL\DEV\Maven\repo\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\JYL\DEV\Maven\repo\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-core\5.0.8.RELEASE\spring-core-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-jcl\5.0.8.RELEASE\spring-jcl-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;D:\JYL\DEV\Maven\repo\com\alibaba\boot\dubbo-spring-boot-starter\0.2.0\dubbo-spring-boot-starter-0.2.0.jar;D:\JYL\DEV\Maven\repo\com\alibaba\dubbo\2.6.2\dubbo-2.6.2.jar;D:\JYL\DEV\Maven\repo\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;D:\JYL\DEV\Maven\repo\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;D:\JYL\DEV\Maven\repo\org\apache\zookeeper\zookeeper\3.4.9\zookeeper-3.4.9.jar;D:\JYL\DEV\Maven\repo\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\JYL\DEV\Maven\repo\jline\jline\0.9.94\jline-0.9.94.jar;D:\JYL\DEV\Maven\repo\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar;D:\JYL\DEV\Maven\repo\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;D:\JYL\DEV\Maven\repo\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;D:\JYL\DEV\Maven\repo\com\google\guava\guava\16.0.1\guava-16.0.1.jar;D:\JYL\DEV\Maven\repo\com\alibaba\boot\dubbo-spring-boot-autoconfigure\0.2.0\dubbo-spring-boot-autoconfigure-0.2.0.jar;D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-api\target\classes demo.spring.boot.dubbo.provider.DemoSpringBootDubboProviderApplication
2018-08-02 20:03:38.348  INFO 7892 --- [           main] c.a.dubbo.common.logger.LoggerFactory    : using logger: com.alibaba.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
2018-08-02 20:03:38.353  INFO 7892 --- [           main] a.b.d.c.e.WelcomeLogoApplicationListener : 

 :: Dubbo Spring Boot (v0.2.0) : https://github.com/apache/incubator-dubbo-spring-boot-project
 :: Dubbo (v2.6.2) : https://github.com/apache/incubator-dubbo
 :: Google group : dev@dubbo.incubator.apache.org

2018-08-02 20:03:38.357  INFO 7892 --- [           main] e.OverrideDubboConfigApplicationListener : Dubbo Config was overridden by externalized configuration {dubbo.application.id=demo-spring-boot-dubbo-provider, dubbo.application.name=demo-spring-boot-dubbo-provider, dubbo.protocol.id=dubbo, dubbo.protocol.name=dubbo, dubbo.protocol.port=20880, dubbo.registry.address=multicast://224.5.6.7:1234, dubbo.registry.id=demo-multicast-registry, dubbo.scan.basePackages=demo.spring.boot.dubbo.provider.service}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

2018-08-02 20:03:38.440  INFO 7892 --- [           main] p.DemoSpringBootDubboProviderApplication : Starting DemoSpringBootDubboProviderApplication on LAPTOP-C375ASPB with PID 7892 (D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-provider\target\classes started by Ji in D:\JYL\DEV\IdeaProjects\demo)
2018-08-02 20:03:38.441  INFO 7892 --- [           main] p.DemoSpringBootDubboProviderApplication : No active profile set, falling back to default profiles: default
2018-08-02 20:03:38.495  INFO 7892 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3ec300f1: startup date [Thu Aug 02 20:03:38 CST 2018]; root of context hierarchy
2018-08-02 20:03:38.884  INFO 7892 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : demo-spring-boot-dubbo-provider, class : com.alibaba.dubbo.config.ApplicationConfig] has been registered.
2018-08-02 20:03:38.886  INFO 7892 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : demo-spring-boot-dubbo-provider] has been registered.
2018-08-02 20:03:38.887  INFO 7892 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : demo-multicast-registry, class : com.alibaba.dubbo.config.RegistryConfig] has been registered.
2018-08-02 20:03:38.887  INFO 7892 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : demo-multicast-registry] has been registered.
2018-08-02 20:03:38.887  INFO 7892 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : dubbo, class : com.alibaba.dubbo.config.ProtocolConfig] has been registered.
2018-08-02 20:03:38.887  INFO 7892 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : dubbo] has been registered.
2018-08-02 20:03:38.971  INFO 7892 --- [           main] b.f.a.ServiceAnnotationBeanPostProcessor :  [DUBBO] BeanNameGenerator bean can't be found in BeanFactory with name [org.springframework.context.annotation.internalConfigurationBeanNameGenerator], dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:38.972  INFO 7892 --- [           main] b.f.a.ServiceAnnotationBeanPostProcessor :  [DUBBO] BeanNameGenerator will be a instance of org.springframework.context.annotation.AnnotationBeanNameGenerator , it maybe a potential problem on bean name generation., dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:38.990  WARN 7892 --- [           main] b.f.a.ServiceAnnotationBeanPostProcessor :  [DUBBO] The BeanDefinition[Root bean: class [com.alibaba.dubbo.config.spring.ServiceBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] of ServiceBean has been registered with name : ServiceBean:greetingServiceImpl:demo.spring.boot.dubbo.api.GreetingService:${spring.application.version}, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:38.990  INFO 7892 --- [           main] b.f.a.ServiceAnnotationBeanPostProcessor :  [DUBBO] 1 annotated Dubbo's @Service Components { [Bean definition with name 'greetingServiceImpl': Generic bean: class [demo.spring.boot.dubbo.provider.service.GreetingServiceImpl]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-provider\target\classes\demo\spring\boot\dubbo\provider\service\GreetingServiceImpl.class]] } were scanned under package[demo.spring.boot.dubbo.provider.service], dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:38.991  WARN 7892 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2018-08-02 20:03:39.191  INFO 7892 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'relaxedDubboConfigBinder' of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:03:39.193  INFO 7892 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'relaxedDubboConfigBinder' of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:03:39.194  INFO 7892 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'relaxedDubboConfigBinder' of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:03:39.279  INFO 7892 --- [           main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : demo-spring-boot-dubbo-provider] have been binding by prefix of configuration properties : dubbo.application
2018-08-02 20:03:39.318  INFO 7892 --- [           main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : demo-multicast-registry] have been binding by prefix of configuration properties : dubbo.registry
2018-08-02 20:03:39.366  INFO 7892 --- [           main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : dubbo] have been binding by prefix of configuration properties : dubbo.protocol
2018-08-02 20:03:39.887  INFO 7892 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-02 20:03:39.897  INFO 7892 --- [           main] com.alibaba.dubbo.config.AbstractConfig  :  [DUBBO] The service ready on spring started. service: demo.spring.boot.dubbo.api.GreetingService, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.017  INFO 7892 --- [           main] com.alibaba.dubbo.config.AbstractConfig  :  [DUBBO] Export dubbo service demo.spring.boot.dubbo.api.GreetingService to local registry, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.017  INFO 7892 --- [           main] com.alibaba.dubbo.config.AbstractConfig  :  [DUBBO] Export dubbo service demo.spring.boot.dubbo.api.GreetingService to url dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&bind.ip=172.20.10.8&bind.port=20880&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.017  INFO 7892 --- [           main] com.alibaba.dubbo.config.AbstractConfig  :  [DUBBO] Register dubbo service demo.spring.boot.dubbo.api.GreetingService url dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&bind.ip=172.20.10.8&bind.port=20880&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 to registry registry://224.5.6.7:1234/com.alibaba.dubbo.registry.RegistryService?application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&pid=7892&registry=multicast&timestamp=1533211419902, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.169  INFO 7892 --- [           main] c.a.d.remoting.transport.AbstractServer  :  [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /172.20.10.8:20880, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.185  INFO 7892 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Register: dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.186  INFO 7892 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Send broadcast message: register dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 to /224.5.6.7:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.186  INFO 7892 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: register dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.188  INFO 7892 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Subscribe: provider://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&category=configurators&check=false&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.188  INFO 7892 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Send broadcast message: subscribe provider://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&category=configurators&check=false&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 to /224.5.6.7:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:40.189  INFO 7892 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: subscribe provider://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&category=configurators&check=false&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:41.194  WARN 7892 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Ignore empty notify urls for subscribe url provider://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&category=configurators&check=false&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:03:41.205  INFO 7892 --- [           main] p.DemoSpringBootDubboProviderApplication : Started DemoSpringBootDubboProviderApplication in 3.141 seconds (JVM running for 3.758)
2018-08-02 20:03:41.213  INFO 7892 --- [pool-1-thread-1] .d.c.e.AwaitingNonWebApplicationListener :  [Dubbo] Current Spring Boot Application is await...

3 demo-spring-boot-dubbo-consumer

3.1 POM 文件钞钙,注意添加 dubbo-spring-boot-starter 依賴

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>demo.spring.boot.dubbo</groupId>
    <artifactId>demo-spring-boot-dubbo-consumer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo-spring-boot-dubbo-consumer</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>0.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    
</project>

3.2 在配置文件 application.properties 中添加 Dubbo 配置信息鳄橘,注意和 demo-spring-boot-dubbo-provider 配置文件的差異

spring.application.name=demo-spring-boot-dubbo-consumer
spring.application.version=1.0

dubbo.application.id=demo-spring-boot-dubbo-consumer
dubbo.application.name=demo-spring-boot-dubbo-consumer

dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880

dubbo.registry.id=demo-multicast-registry
dubbo.registry.address=multicast://224.5.6.7:1234

3.3 定義一個定時調(diào)用 RPC 服務(wù)的任務(wù)

package demo.spring.boot.dubbo.consumer;

import com.alibaba.dubbo.config.annotation.Reference;
import demo.spring.boot.dubbo.api.GreetingService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class Consumer {

    @Reference(version = "${spring.application.version}",
        application = "${spring.application.id}",
        registry = "${dubbo.registry.address}")
    private GreetingService greetingService;
    
    @Scheduled(fixedRate = 3000)
    public void consume() {
        System.out.println(greetingService.welcome("Dubbo"));
    }
}

3.4 應(yīng)用啟動類開啟對定時任務(wù)的支持

package demo.spring.boot.dubbo.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class DemoSpringBootDubboConsumerApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(DemoSpringBootDubboConsumerApplication.class, args);
    }
}

啟動應(yīng)用,從 demo-spring-boot-dubbo-consumer 日志中可以看出每 3 秒調(diào)用一次 Dubbo RPC 服務(wù)

C:\Dev\Java\jdk1.8.0_172\bin\java.exe "-javaagent:C:\Dev\JetBrains\IntelliJ IDEA 2018.1.2\lib\idea_rt.jar=51568:C:\Dev\JetBrains\IntelliJ IDEA 2018.1.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Dev\Java\jdk1.8.0_172\jre\lib\charsets.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\deploy.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\access-bridge-64.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\cldrdata.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\dnsns.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\jaccess.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\jfxrt.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\localedata.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\nashorn.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunec.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunjce_provider.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunmscapi.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\sunpkcs11.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\ext\zipfs.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\javaws.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jce.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jfr.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jfxswt.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\jsse.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\management-agent.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\plugin.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\resources.jar;C:\Dev\Java\jdk1.8.0_172\jre\lib\rt.jar;D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-consumer\target\classes;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot-starter\2.0.4.RELEASE\spring-boot-starter-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot\2.0.4.RELEASE\spring-boot-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-context\5.0.8.RELEASE\spring-context-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-aop\5.0.8.RELEASE\spring-aop-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-beans\5.0.8.RELEASE\spring-beans-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-expression\5.0.8.RELEASE\spring-expression-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot-autoconfigure\2.0.4.RELEASE\spring-boot-autoconfigure-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\boot\spring-boot-starter-logging\2.0.4.RELEASE\spring-boot-starter-logging-2.0.4.RELEASE.jar;D:\JYL\DEV\Maven\repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\JYL\DEV\Maven\repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\JYL\DEV\Maven\repo\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;D:\JYL\DEV\Maven\repo\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;D:\JYL\DEV\Maven\repo\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\JYL\DEV\Maven\repo\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-core\5.0.8.RELEASE\spring-core-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\springframework\spring-jcl\5.0.8.RELEASE\spring-jcl-5.0.8.RELEASE.jar;D:\JYL\DEV\Maven\repo\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;D:\JYL\DEV\Maven\repo\com\alibaba\boot\dubbo-spring-boot-starter\0.2.0\dubbo-spring-boot-starter-0.2.0.jar;D:\JYL\DEV\Maven\repo\com\alibaba\dubbo\2.6.2\dubbo-2.6.2.jar;D:\JYL\DEV\Maven\repo\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;D:\JYL\DEV\Maven\repo\org\jboss\netty\netty\3.2.5.Final\netty-3.2.5.Final.jar;D:\JYL\DEV\Maven\repo\org\apache\zookeeper\zookeeper\3.4.9\zookeeper-3.4.9.jar;D:\JYL\DEV\Maven\repo\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\JYL\DEV\Maven\repo\jline\jline\0.9.94\jline-0.9.94.jar;D:\JYL\DEV\Maven\repo\io\netty\netty\3.10.5.Final\netty-3.10.5.Final.jar;D:\JYL\DEV\Maven\repo\org\apache\curator\curator-framework\2.12.0\curator-framework-2.12.0.jar;D:\JYL\DEV\Maven\repo\org\apache\curator\curator-client\2.12.0\curator-client-2.12.0.jar;D:\JYL\DEV\Maven\repo\com\google\guava\guava\16.0.1\guava-16.0.1.jar;D:\JYL\DEV\Maven\repo\com\alibaba\boot\dubbo-spring-boot-autoconfigure\0.2.0\dubbo-spring-boot-autoconfigure-0.2.0.jar;D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-api\target\classes demo.spring.boot.dubbo.consumer.DemoSpringBootDubboConsumerApplication
2018-08-02 20:19:01.021  INFO 17432 --- [           main] c.a.dubbo.common.logger.LoggerFactory    : using logger: com.alibaba.dubbo.common.logger.slf4j.Slf4jLoggerAdapter
2018-08-02 20:19:01.028  INFO 17432 --- [           main] a.b.d.c.e.WelcomeLogoApplicationListener : 

 :: Dubbo Spring Boot (v0.2.0) : https://github.com/apache/incubator-dubbo-spring-boot-project
 :: Dubbo (v2.6.2) : https://github.com/apache/incubator-dubbo
 :: Google group : dev@dubbo.incubator.apache.org

2018-08-02 20:19:01.030  INFO 17432 --- [           main] e.OverrideDubboConfigApplicationListener : Dubbo Config was overridden by externalized configuration {dubbo.application.id=demo-spring-boot-dubbo-consumer, dubbo.application.name=demo-spring-boot-dubbo-consumer, dubbo.protocol.id=dubbo, dubbo.protocol.name=dubbo, dubbo.protocol.port=20880, dubbo.registry.address=multicast://224.5.6.7:1234, dubbo.registry.id=demo-multicast-registry}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

2018-08-02 20:19:01.124  INFO 17432 --- [           main] c.DemoSpringBootDubboConsumerApplication : Starting DemoSpringBootDubboConsumerApplication on LAPTOP-C375ASPB with PID 17432 (D:\JYL\DEV\IdeaProjects\demo\demo-spring-boot-dubbo-consumer\target\classes started by Ji in D:\JYL\DEV\IdeaProjects\demo)
2018-08-02 20:19:01.125  INFO 17432 --- [           main] c.DemoSpringBootDubboConsumerApplication : No active profile set, falling back to default profiles: default
2018-08-02 20:19:01.190  INFO 17432 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5b0abc94: startup date [Thu Aug 02 20:19:01 CST 2018]; root of context hierarchy
2018-08-02 20:19:01.616  INFO 17432 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : demo-spring-boot-dubbo-consumer, class : com.alibaba.dubbo.config.ApplicationConfig] has been registered.
2018-08-02 20:19:01.616  INFO 17432 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : demo-spring-boot-dubbo-consumer] has been registered.
2018-08-02 20:19:01.616  INFO 17432 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : demo-multicast-registry, class : com.alibaba.dubbo.config.RegistryConfig] has been registered.
2018-08-02 20:19:01.616  INFO 17432 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : demo-multicast-registry] has been registered.
2018-08-02 20:19:01.616  INFO 17432 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The dubbo config bean definition [name : dubbo, class : com.alibaba.dubbo.config.ProtocolConfig] has been registered.
2018-08-02 20:19:01.621  INFO 17432 --- [           main] .a.d.c.s.c.a.DubboConfigBindingRegistrar : The BeanPostProcessor bean definition [com.alibaba.dubbo.config.spring.beans.factory.annotation.DubboConfigBindingBeanPostProcessor] for dubbo config bean [name : dubbo] has been registered.
2018-08-02 20:19:01.862  INFO 17432 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration' of type [com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration$$EnhancerBySpringCGLIB$$944554c6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:19:01.954  INFO 17432 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'relaxedDubboConfigBinder' of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:19:01.958  INFO 17432 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'relaxedDubboConfigBinder' of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:19:01.958  INFO 17432 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'relaxedDubboConfigBinder' of type [com.alibaba.boot.dubbo.autoconfigure.RelaxedDubboConfigBinder] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-08-02 20:19:02.376  INFO 17432 --- [           main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : demo-spring-boot-dubbo-consumer] have been binding by prefix of configuration properties : dubbo.application
2018-08-02 20:19:02.386  INFO 17432 --- [           main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : demo-multicast-registry] have been binding by prefix of configuration properties : dubbo.registry
2018-08-02 20:19:02.443  INFO 17432 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Load registry store file C:\Users\Ji\.dubbo\dubbo-registry-demo-spring-boot-dubbo-consumer-224.5.6.7:1234.cache, data: {demo.spring.boot.dubbo.api.GreetingService:1.0=dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=10680&revision=1.0&side=provider&timestamp=1533211117636&version=1.0}, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.474  INFO 17432 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Register: consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=consumers&check=false&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.474  INFO 17432 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Send broadcast message: register consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=consumers&check=false&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0 to /224.5.6.7:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.474  INFO 17432 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Subscribe: consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=providers,configurators,routers&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.474  INFO 17432 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: register consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=consumers&check=false&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.475  INFO 17432 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Send broadcast message: subscribe consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=providers,configurators,routers&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0 to /224.5.6.7:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.475  INFO 17432 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: subscribe consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=providers,configurators,routers&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.476  INFO 17432 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: register dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.476  INFO 17432 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Notify urls for subscribe url consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=providers,configurators,routers&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0, urls: [dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0], dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.818  INFO 17432 --- [egistryReceiver] c.a.d.remoting.transport.AbstractClient  :  [DUBBO] Successed connect to server /172.20.10.8:20880 from NettyClient 172.20.10.8 using dubbo version 2.6.2, channel is NettyChannel [channel=[id: 0x01d8a8f3, /172.20.10.8:51573 => /172.20.10.8:20880]], dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.819  INFO 17432 --- [egistryReceiver] c.a.d.remoting.transport.AbstractClient  :  [DUBBO] Start NettyClient LAPTOP-C375ASPB/172.20.10.8 connect to the server /172.20.10.8:20880, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.871  INFO 17432 --- [           main] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Notify urls for subscribe url consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=providers,configurators,routers&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0, urls: [dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0], dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.878  INFO 17432 --- [           main] com.alibaba.dubbo.config.AbstractConfig  :  [DUBBO] Refer dubbo service demo.spring.boot.dubbo.api.GreetingService from url multicast://224.5.6.7:1234/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=demo-spring-boot-dubbo-consumer&check=false&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&register.ip=172.20.10.8&remote.timestamp=1533211419902&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.886  INFO 17432 --- [           main] c.a.d.c.s.b.f.a.ReferenceBeanBuilder     : <dubbo:reference object="com.alibaba.dubbo.common.bytecode.proxy0@23aa363a" singleton="true" uniqueServiceName="demo.spring.boot.dubbo.api.GreetingService:1.0" interface="demo.spring.boot.dubbo.api.GreetingService" generic="false" version="1.0" id="demo.spring.boot.dubbo.api.GreetingService" /> has been built.
2018-08-02 20:19:02.921  INFO 17432 --- [           main] .f.a.DubboConfigBindingBeanPostProcessor : The properties of bean [name : dubbo] have been binding by prefix of configuration properties : dubbo.protocol
2018-08-02 20:19:03.108  INFO 17432 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-02 20:19:03.123  INFO 17432 --- [           main] s.a.ScheduledAnnotationBeanPostProcessor : No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
2018-08-02 20:19:03.134  INFO 17432 --- [           main] c.DemoSpringBootDubboConsumerApplication : Started DemoSpringBootDubboConsumerApplication in 2.446 seconds (JVM running for 3.146)
2018-08-02 20:19:03.139  INFO 17432 --- [pool-1-thread-1] .d.c.e.AwaitingNonWebApplicationListener :  [Dubbo] Current Spring Boot Application is await...
Welcome Dubbo at 2018-08-02T20:19:03.234
Welcome Dubbo at 2018-08-02T20:19:06.149
Welcome Dubbo at 2018-08-02T20:19:09.137
Welcome Dubbo at 2018-08-02T20:19:12.136
Welcome Dubbo at 2018-08-02T20:19:15.140
Welcome Dubbo at 2018-08-02T20:19:18.132
Welcome Dubbo at 2018-08-02T20:19:21.137
Welcome Dubbo at 2018-08-02T20:19:24.136
......

再看一下 demo-spring-boot-dubbo-provider 工程日志打印芒炼,也有 Dubbo RPC 服務(wù)被調(diào)用的記錄

......
2018-08-02 20:03:41.205  INFO 7892 --- [           main] p.DemoSpringBootDubboProviderApplication : Started DemoSpringBootDubboProviderApplication in 3.141 seconds (JVM running for 3.758)
2018-08-02 20:03:41.213  INFO 7892 --- [pool-1-thread-1] .d.c.e.AwaitingNonWebApplicationListener :  [Dubbo] Current Spring Boot Application is await...
2018-08-02 20:19:02.474  INFO 7892 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: register consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=consumers&check=false&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.475  INFO 7892 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: subscribe consumer://172.20.10.8/demo.spring.boot.dubbo.api.GreetingService?application=demo-spring-boot-dubbo-consumer&category=providers,configurators,routers&dubbo=2.6.2&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=17432&revision=1.0&side=consumer&timestamp=1533212342396&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.475  INFO 7892 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Send broadcast message: register dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 to /224.5.6.7:1234, dubbo version: 2.6.2, current host: 172.20.10.8
2018-08-02 20:19:02.476  INFO 7892 --- [egistryReceiver] c.a.d.r.multicast.MulticastRegistry      :  [DUBBO] Receive multicast message: register dubbo://172.20.10.8:20880/demo.spring.boot.dubbo.api.GreetingService?anyhost=true&application=demo-spring-boot-dubbo-provider&dubbo=2.6.2&generic=false&interface=demo.spring.boot.dubbo.api.GreetingService&methods=welcome&pid=7892&revision=1.0&side=provider&timestamp=1533211419902&version=1.0 from /172.20.10.8:1234, dubbo version: 2.6.2, current host: 172.20.10.8
Welcome Dubbo at 2018-08-02T20:19:03.234
Welcome Dubbo at 2018-08-02T20:19:06.149
Welcome Dubbo at 2018-08-02T20:19:09.137
Welcome Dubbo at 2018-08-02T20:19:12.136
Welcome Dubbo at 2018-08-02T20:19:15.140
Welcome Dubbo at 2018-08-02T20:19:18.132
......

附:工程目錄

demo-spring-boot-dubbo-api
demo-spring-boot-dubbo-provider
demo-spring-boot-dubbo-consumer

官方參考:
Apache Dubbo
GitHub apache/incubator-dubbo
GitHub apache/incubator-dubbo-spring-boot-project

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末瘫怜,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子本刽,更是在濱河造成了極大的恐慌鲸湃,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件子寓,死亡現(xiàn)場離奇詭異暗挑,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)斜友,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進(jìn)店門炸裆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人鲜屏,你說我怎么就攤上這事烹看。” “怎么了墙歪?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵听系,是天一觀的道長贝奇。 經(jīng)常有香客問我虹菲,道長,這世上最難降的妖魔是什么掉瞳? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任毕源,我火速辦了婚禮浪漠,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘霎褐。我一直安慰自己址愿,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布冻璃。 她就那樣靜靜地躺著响谓,像睡著了一般。 火紅的嫁衣襯著肌膚如雪省艳。 梳的紋絲不亂的頭發(fā)上娘纷,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天,我揣著相機(jī)與錄音跋炕,去河邊找鬼赖晶。 笑死,一個胖子當(dāng)著我的面吹牛辐烂,可吹牛的內(nèi)容都是我干的遏插。 我是一名探鬼主播,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼纠修,長吁一口氣:“原來是場噩夢啊……” “哼胳嘲!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起分瘾,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤胎围,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后德召,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體白魂,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年上岗,在試婚紗的時候發(fā)現(xiàn)自己被綠了福荸。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡肴掷,死狀恐怖敬锐,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情呆瞻,我是刑警寧澤台夺,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站痴脾,受9級特大地震影響颤介,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一滚朵、第九天 我趴在偏房一處隱蔽的房頂上張望冤灾。 院中可真熱鬧,春花似錦辕近、人聲如沸韵吨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽归粉。三九已至,卻和暖如春漏峰,著一層夾襖步出監(jiān)牢的瞬間盏浇,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工芽狗, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留绢掰,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓童擎,卻偏偏與公主長得像滴劲,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子顾复,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容

  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,803評論 6 342
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理班挖,服務(wù)發(fā)現(xiàn),斷路器芯砸,智...
    卡卡羅2017閱讀 134,651評論 18 139
  • 最近規(guī)劃壓力測試萧芙,測試的結(jié)果不是很滿意,由于服務(wù)資源的問題假丧,整體服務(wù)跑起來不好判斷性能瓶頸双揪,于是想做一個精簡的服務(wù)...
    湯湯的閱讀 298評論 0 1
  • https://github.com/teaey/spring-boot-starter-dubbo
    183207efd207閱讀 240評論 0 0
  • WebRTC(Web Real-Time Communication)是 Google于2010你那以$6829萬...
    JunChow520閱讀 4,335評論 0 2