Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
程序猿小郑
microservices-platform
提交
06b77a83
microservices-platform
项目概览
程序猿小郑
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
06b77a83
编写于
4月 14, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化自定义负载均衡
上级
a047cf00
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
24 deletion
+31
-24
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/LbIsolationAutoConfigure.java
...a/com/central/common/ribbon/LbIsolationAutoConfigure.java
+20
-6
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/config/RuleConfigure.java
.../java/com/central/common/ribbon/config/RuleConfigure.java
+0
-16
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/rule/VersionIsolationRule.java
.../com/central/common/ribbon/rule/VersionIsolationRule.java
+11
-2
未找到文件。
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/LbIsolationAutoConfigure.java
浏览文件 @
06b77a83
package
com.central.common.ribbon
;
import
com.alibaba.cloud.nacos.ribbon.NacosServer
;
import
com.central.common.constant.ConfigConstants
;
import
com.central.common.ribbon.config.RuleConfigure
;
import
com.central.common.ribbon.rule.VersionIsolationRule
;
import
com.netflix.loadbalancer.IRule
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration
;
import
org.springframework.context.annotation.Bean
;
/**
*
Ribbon扩展配置类
*
自定义负载均衡配置
*
* @author zlt
* @date 2018/11/17 9:24
* @date 2019/9/3
* <p>
* Blog: https://blog.csdn.net/zlt2000
* Github: https://github.com/zlt2000
*/
@ConditionalOnProperty
(
value
=
ConfigConstants
.
CONFIG_RIBBON_ISOLATION_ENABLED
,
havingValue
=
"true"
)
@
RibbonClients
(
defaultConfiguration
=
{
RuleConfigure
.
class
}
)
@
AutoConfigureBefore
(
RibbonClientConfiguration
.
class
)
public
class
LbIsolationAutoConfigure
{
@Bean
@ConditionalOnClass
(
NacosServer
.
class
)
@ConditionalOnMissingBean
public
IRule
versionIsolationRule
()
{
return
new
VersionIsolationRule
();
}
}
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/config/RuleConfigure.java
已删除
100644 → 0
浏览文件 @
a047cf00
package
com.central.common.ribbon.config
;
import
com.central.common.ribbon.rule.CustomIsolationRule
;
import
com.netflix.loadbalancer.IRule
;
import
org.springframework.context.annotation.Bean
;
/**
* @author zlt
* @date 2019/9/3
*/
public
class
RuleConfigure
{
@Bean
public
IRule
isolationRule
()
{
return
new
CustomIsolationRule
();
}
}
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/rule/
Custom
IsolationRule.java
→
zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/rule/
Version
IsolationRule.java
浏览文件 @
06b77a83
...
...
@@ -12,12 +12,21 @@ import java.util.List;
import
java.util.stream.Collectors
;
/**
* 自定义隔离随机规则
* 根据实例版本号隔离规则
* 详细用法:https://mp.weixin.qq.com/s/9XQ-SIbYsov3KBx9TGFN0g
*
* 实例获取规则顺序如下(不满足则走下一个规则):
* 1. 相同版本号的实例
* 2. 无版本号的实例
* 3. 所有实例中轮询
*
* @author zlt
* @date 2019/9/3
* <p>
* Blog: https://blog.csdn.net/zlt2000
* Github: https://github.com/zlt2000
*/
public
class
Custom
IsolationRule
extends
RoundRobinRule
{
public
class
Version
IsolationRule
extends
RoundRobinRule
{
private
final
static
String
KEY_DEFAULT
=
"default"
;
/**
* 优先根据版本号取实例
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录