Spring Boot Dubbo applications.properties 配置清单

开发 开发工具
根据 starter 工程源码,可以看出 application.properties 对应的 Dubbo 配置类 DubboProperties 。包括了扫描路径、应用配置类、注册中心配置类和服务协议类。

[[190612]]

本文提纲

一、前言

二、applications.properties 配置清单

三、@Service 服务提供者常用配置

四、@Reference 服务消费者常用配置

五、小结

运行环境:JDK 7 或 8、Maven 3.0+

技术栈:SpringBoot 1.5+、、Dubbo 2.5+

一、前言

在泥瓦匠出的《Springboot 整合 Dubbo/ZooKeeper 详解 SOA 案例》《如何在 Spring Boot 使用 Dubbo Activate 扩展点》两篇文章后,很多人跟我聊 Spring Boot 整合 Dubbo 的细节问题。当然最多的是配置问题,比如

Q:如果一个程序既提供服务又是消费者怎么配置 scan package?

A(群友周波): 就是 com.xxx.provider 生产者,com.xxx.consumer 消费者,那么 scan package 就设置到 com.xxx

Q:如何设置消费者调用生产者的超时时间?

A:目前不能通过 application.properties 定义。@Reference timeout

Q:consumer 怎么配置接入多个 provider?

A:@Reference 可以指定不同的 register。register (注册中心 like provider container)里面可以对应多个 provider

Q: @Service(version = "1.0.0") 这个 1.0.0 可以从 application.properties 配置文件中读取吗?可以区分不同的环境,可以统一升级管理

A:占时还没有解决... 但是应用环境,如:dev/test/run 可以使用下面的配置

spring.dubbo.application.environment

这里 Spring Boot 整合 Dubbo 的项目依赖了 spring-boot-starter-dubbo 工程,该项目地址是https://github.com/teaey/spring-boot-starter-dubbo。 

二、applications.properties 配置清单

根据 starter 工程源码,可以看出 application.properties 对应的 Dubbo 配置类 DubboProperties 。包括了扫描路径、应用配置类、注册中心配置类和服务协议类。

具体常用配置下:

扫描包路径:指的是 Dubbo 服务注解的服务包路径

## Dubbo 配置 
# 扫描包路径 
spring.dubbo.scan=org.spring.springboot.dubbo 
  • 1.
  • 2.
  • 3.

应用配置类:关于 Dubbo 应用级别的配置

## Dubbo 应用配置 
// 应用名称 
spring.dubbo.application.name=xxx 
 
// 模块版本 
spring.dubbo.application.version=xxx 
 
// 应用负责人 
spring.dubbo.application.owner=xxx 
 
// 组织名(BU或部门) 
spring.dubbo.application.organization=xxx 
 
// 分层 
spring.dubbo.application.architecture=xxx 
 
// 环境,如:dev/test/run 
spring.dubbo.application.environment=xxx 
 
// Java代码编译器 
spring.dubbo.application.compiler=xxx 
 
// 日志输出方式 
spring.dubbo.application.logger=xxx 
 
// 注册中心 0 
spring.dubbo.application.registries[0].address=zookeeper://127.0.0.1:2181=xxx 
// 注册中心 1 
spring.dubbo.application.registries[1].address=zookeeper://127.0.0.1:2181=xxx 
 
// 服务监控 
spring.dubbo.application.monitor.address=xxx 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.

这里注意多个注册中心的配置方式。下面介绍单个注册中心的配置方式。

注册中心配置类:常用 ZooKeeper 作为注册中心进行服务注册。

# Dubbo 注册中心配置类 
// 注册中心地址 
spring.dubbo.application.registries.address=xxx 
 
// 注册中心登录用户名 
spring.dubbo.application.registries.username=xxx 
 
// 注册中心登录密码 
spring.dubbo.application.registries.password=xxx 
 
// 注册中心缺省端口 
spring.dubbo.application.registries.port=xxx 
 
// 注册中心协议 
spring.dubbo.application.registries.protocol=xxx 
 
// 客户端实现 
spring.dubbo.application.registries.transporter=xxx 
 
spring.dubbo.application.registries.server=xxx 
 
spring.dubbo.application.registries.client=xxx 
 
spring.dubbo.application.registries.cluster=xxx 
 
spring.dubbo.application.registries.group=xxx 
 
spring.dubbo.application.registries.version=xxx 
 
// 注册中心请求超时时间(毫秒) 
spring.dubbo.application.registries.timeout=xxx 
 
// 注册中心会话超时时间(毫秒) 
spring.dubbo.application.registries.session=xxx 
 
// 动态注册中心列表存储文件 
spring.dubbo.application.registries.file=xxx 
 
// 停止时等候完成通知时间 
spring.dubbo.application.registries.wait=xxx 
 
// 启动时检查注册中心是否存在 
spring.dubbo.application.registries.check=xxx 
 
// 在该注册中心上注册是动态的还是静态的服务 
spring.dubbo.application.registries.dynamic=xxx 
 
// 在该注册中心上服务是否暴露 
spring.dubbo.application.registries.register=xxx 
 
// 在该注册中心上服务是否引用 
spring.dubbo.application.registries.subscribe=xxx 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.

服务协议配置类:

## Dubbo 服务协议配置 
 
 
// 服务协议 
spring.dubbo.application.protocol.name=xxx 
 
// 服务IP地址(多网卡时使用) 
spring.dubbo.application.protocol.host=xxx 
 
// 服务端口 
spring.dubbo.application.protocol.port=xxx 
 
// 上下文路径 
spring.dubbo.application.protocol.contextpath=xxx 
 
// 线程池类型 
spring.dubbo.application.protocol.threadpool=xxx 
 
// 线程池大小(固定大小) 
spring.dubbo.application.protocol.threads=xxx 
 
// IO线程池大小(固定大小) 
spring.dubbo.application.protocol.iothreads=xxx 
 
// 线程池队列大小 
spring.dubbo.application.protocol.queues=xxx 
 
// 最大接收连接数 
spring.dubbo.application.protocol.accepts=xxx 
 
// 协议编码 
spring.dubbo.application.protocol.codec=xxx 
 
// 序列化方式 
spring.dubbo.application.protocol.serialization=xxx 
 
// 字符集 
spring.dubbo.application.protocol.charset=xxx 
 
// 最大请求数据长度 
spring.dubbo.application.protocol.payload=xxx 
 
// 缓存区大小 
spring.dubbo.application.protocol.buffer=xxx 
 
// 心跳间隔 
spring.dubbo.application.protocol.heartbeat=xxx 
 
// 访问日志 
spring.dubbo.application.protocol.accesslog=xxx 
 
// 网络传输方式 
spring.dubbo.application.protocol.transporter=xxx 
 
// 信息交换方式 
spring.dubbo.application.protocol.exchanger=xxx 
 
// 信息线程模型派发方式 
spring.dubbo.application.protocol.dispatcher=xxx 
 
// 对称网络组网方式 
spring.dubbo.application.protocol.networker=xxx 
 
// 服务器端实现 
spring.dubbo.application.protocol.server=xxx 
 
// 客户端实现 
spring.dubbo.application.protocol.client=xxx 
 
// 支持的telnet命令,多个命令用逗号分隔 
spring.dubbo.application.protocol.telnet=xxx 
 
// 命令行提示符 
spring.dubbo.application.protocol.prompt=xxx 
 
// status检查 
spring.dubbo.application.protocol.status=xxx 
 
// 是否注册 
spring.dubbo.application.protocol.status=xxx 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.

三、@Service 服务提供者常用配置

常用 @Service 配置的如下

  • version 版本
  • group 分组
  • provider 提供者
  • protocol 服务协议
  • monitor 服务监控
  • registry 服务注册

四、@Reference 服务消费者常用配置

常用 @Reference 配置的如下

  • version 版本
  • group 分组
  • timeout 消费者调用提供者的超时时间
  • consumer 服务消费者
  • monitor 服务监控
  • registry 服务注册

五、小结

主要介绍了 Spring Boot Dubbo 整合中的细节问题大集合。

【本文为51CTO专栏作者“李强强”的原创稿件,转载请通过51CTO联系作者获取授权】

戳这里,看该作者更多好文

责任编辑:武晓燕 来源: 51CTO专栏
相关推荐

2023-11-01 08:30:20

SpringYAML

2019-01-15 11:40:14

开发技能代码

2018-10-10 09:30:29

Spring Boot知识框架

2017-05-09 10:34:21

Spring BootDubbo Activ扩展

2017-04-28 08:32:40

Spring BootDubbo Activ使用

2021-08-06 08:04:14

Spring Boot自动配置

2017-03-23 09:29:06

2023-11-01 15:07:51

环境配置方式

2022-09-02 08:19:37

spring配置加载

2025-02-27 00:10:19

2022-04-27 08:55:01

Spring外部化配置

2022-08-11 09:17:38

架构开发

2024-10-18 16:21:49

SpringPOM

2023-10-18 08:12:34

Spring自动配置

2020-12-31 07:55:33

spring bootMybatis数据库

2024-04-23 14:13:38

开发配置文件

2023-10-30 15:11:57

2020-11-05 10:40:07

Spring Boot多模块Java

2021-09-30 06:31:12

Spring Boot配置密码

2009-06-05 10:35:02

struts.prop配置文件
点赞
收藏

51CTO技术栈公众号