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 文件
4.0.0
demo.spring.boot.dubbo
demo-spring-boot-dubbo-api
1.0-SNAPSHOT
jar
org.apache.maven.plugins
maven-compiler-plugin
3.7.0
1.8
UTF-8
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
依赖
4.0.0
demo.spring.boot.dubbo
demo-spring-boot-dubbo-provider
0.0.1-SNAPSHOT
jar
demo-spring-boot-dubbo-provider
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter
com.alibaba.boot
dubbo-spring-boot-starter
0.2.0
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
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 : [email protected]
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×tamp=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×tamp=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®istry=multicast×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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
依赖
4.0.0
demo.spring.boot.dubbo
demo-spring-boot-dubbo-consumer
0.0.1-SNAPSHOT
jar
demo-spring-boot-dubbo-consumer
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter
com.alibaba.boot
dubbo-spring-boot-starter
0.2.0
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
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 : [email protected]
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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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×tamp=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®ister.ip=172.20.10.8&remote.timestamp=1533211419902&revision=1.0&side=consumer×tamp=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 : 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×tamp=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×tamp=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×tamp=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×tamp=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
......
附:工程目录
官方参考:
Apache Dubbo
GitHub apache/incubator-dubbo
GitHub apache/incubator-dubbo-spring-boot-project