Spring Boot 集成 Dubbo

Dubbo 是阿里巴巴开源的基于 Java 的高性能 RPC 框架,本文介绍 Spring Boot 集成 Dubbo 的开发过程,更多有关 Dubbo 的技术细节参考 Dubbo 开发

首先,使用 IntelliJ IDEA 创建一个包含 3 个 Module 的工程,参考:
IntelliJ IDEA 创建多 Module 工程


demo-spring-boot-dubbo-api 是 Maven 工程,定义 Dubbo RPC 服务接口、服务模型和服务异常,通常打包成 jar 被 Dubbo 服务提供方和消费方依赖。
demo-spring-boot-dubbo-provider 是 Spring Boot 工程,Dubbo 服务提供方。
demo-spring-boot-dubbo-consumer 是 Spring Boot 工程,Dubbo 服务消费方。

如何使用 IntelliJ IDEA 创建 Maven 和 Spring Boot 工程请参考:
IntelliJ IDEA 创建 Maven 工程
IntelliJ IDEA 创建 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 格式配置文件,否则无法成功注册服务(暂时还没追查具体原因)

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 服务接口实现类

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 不需要修改自动生成的应用启动类

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);
    }
}

启动应用,日志如下,从 MulticastRegistry 相关日志信息中可以看见服务已注册成功。

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 定义一个定时调用 RPC 服务的任务

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 应用启动类开启对定时任务的支持

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);
    }
}

启动应用,从 demo-spring-boot-dubbo-consumer 日志中可以看出每 3 秒调用一次 Dubbo RPC 服务

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 服务被调用的记录

......
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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,980评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,178评论 2 380
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,868评论 0 336
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,498评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,492评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,521评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,910评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,569评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,793评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,559评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,639评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,342评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,931评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,904评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,144评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,833评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,350评论 2 342

推荐阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,717评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,580评论 18 139
  • 最近规划压力测试,测试的结果不是很满意,由于服务资源的问题,整体服务跑起来不好判断性能瓶颈,于是想做一个精简的服务...
    汤汤的阅读 292评论 0 1
  • https://github.com/teaey/spring-boot-starter-dubbo
    183207efd207阅读 236评论 0 0
  • WebRTC(Web Real-Time Communication)是 Google于2010你那以$6829万...
    JunChow520阅读 4,319评论 0 2