内容简介:今天给大家分享一篇我在学习Nacos想用它做灰度发布的思路分享。什么是灰度发布请看如下链接:那么进入正题,在netflix全家桶相继凉凉后,Ribbon组件确一直坚挺包括在Spring Cloud Alibaba Nacos中也在使用。其实要基于Nacos做灰度发布,也是在Ribbon上做手脚。
今天给大家分享一篇我在学习Nacos想用它做灰度发布的思路分享。
什么是灰度发布请看如下链接: baike.baidu.com/item/灰度发布/7…
那么进入正题,在netflix全家桶相继凉凉后,Ribbon组件确一直坚挺包括在Spring Cloud Alibaba Nacos中也在使用。其实要基于Nacos做灰度发布,也是在Ribbon上做手脚。
第一步扩展Metadata Predicate
public abstract class DiscoveryEnabledPredicate extends AbstractServerPredicate { @Override public boolean apply(@Nullable PredicateKey input) { //由于NacosServer继承了Ribbon的Server,那么扩展成其他配置中心同理 return input != null && input.getServer() instanceof NacosServer && apply((NacosServer) input.getServer()); } protected abstract boolean apply(NacosServer nacosServer); } 复制代码
public class MetadataAwarePredicate extends DiscoveryEnabledPredicate{ @Override protected boolean apply(NacosServer nacosServer) { //根据客户端传入的版本号进行过滤,此处可自行设计扩展 HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder .getRequestAttributes()).getRequest(); String versionNo = request.getHeader("version"); Map<String,String> versionMap = new HashMap<>(); versionMap.put("version",versionNo); final Set<Map.Entry<String,String>> attributes = Collections.unmodifiableSet(versionMap.entrySet()); final Map<String,String> metadata = nacosServer.getInstance().getMetadata(); return metadata.entrySet().containsAll(attributes); } } 复制代码
第二步扩展Metadata Rule
public abstract class DiscoveryEnabledRule extends PredicateBasedRule { private final CompositePredicate predicate; public DiscoveryEnabledRule(DiscoveryEnabledPredicate discoveryEnabledPredicate) { Assert.notNull(discoveryEnabledPredicate, "Parameter 'discoveryEnabledPredicate' can't be null"); this.predicate = createCompositePredicate(discoveryEnabledPredicate,new AvailabilityPredicate(this,null)); } @Override public AbstractServerPredicate getPredicate() { return this.predicate; } private CompositePredicate createCompositePredicate(DiscoveryEnabledPredicate discoveryEnabledPredicate, AvailabilityPredicate availabilityPredicate) { return CompositePredicate.withPredicates(discoveryEnabledPredicate, availabilityPredicate) .build(); } } 复制代码
public class MetadataAwareRule extends DiscoveryEnabledRule{ public MetadataAwareRule(){ this(new MetadataAwarePredicate()); } public MetadataAwareRule(DiscoveryEnabledPredicate predicate) { super(predicate); } } 复制代码
第三步丢进Spring容器
@Configuration public class RibbonDiscoveryRuleAutoConfiguration { @Bean public DiscoveryEnabledRule metadataAwareRule(){ return new MetadataAwareRule(); } } 复制代码
最后
灰度发布其实是一个挺复杂的系统,上述代码只是给大家提供一丢丢思路,本菜也在学习中。
同时给大家推荐一个相当不错的灰度发布框架(军哥的作品), github.com/Nepxion/Dis…
另外,本菜最近失业了,有需要搬砖的联系我啊,坐标:广州、长沙即可(专业研究CRUD 3-4年)
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Spring Cloud实践:降级、限流、滚动、灰度、AB、金丝雀的实现思路
- 图像灰度化
- 服务灰度发布设计
- iOS APP 灰度发布方案
- Istio,灰度发布从未如此轻松!!!
- 前端工程化:构建、部署、灰度
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
用UML构建Web应用
科纳尔伦 (Conallen Jim) / 陈起 / 中国电力出版社 / 2003-11 / 39.0
用UML构建Web应用(第2版),ISBN:9787508315577,作者:(美)Jim Conallen著;陈起,英宇译;陈起译一起来看看 《用UML构建Web应用》 这本书的介绍吧!
CSS 压缩/解压工具
在线压缩/解压 CSS 代码
RGB转16进制工具
RGB HEX 互转工具