当前位置: 首页 > news >正文

做gif动图的素材网站北京网站开发网络公司

做gif动图的素材网站,北京网站开发网络公司,意大利 网站设计,wordpress分类高亮其实在项目中直接使用ribbon时不多#xff0c;大多是使用feign的#xff0c;其实feign底层也是通过ribbon构建的#xff0c;主要记忆一下计算规则#xff0c;ribbon的源码还是很不错的#xff0c;还是值得学习的。 1、添加pom dependencygroupIdorg.spr…其实在项目中直接使用ribbon时不多大多是使用feign的其实feign底层也是通过ribbon构建的主要记忆一下计算规则ribbon的源码还是很不错的还是值得学习的。 1、添加pom dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-ribbon/artifactId /dependency2、启动类注解 我没有在启动类添加注解直接另外一个配置类Configuration添加 3、添加配置 # 默认是轮训都有随机、加权响应时间、重试看具体业务和服务器搭配 #eureka-client.ribbon.NFLoadBalancerRuleClassNamecom.netflix.loadbalancer.RoundRobinRule4、参照源码规则自己编写规则 这里是通过hashcode在hash闭环定义的当每台服务器hashcode在hash闭环的对应位置后每次请求直接定位到hash中顺时针寻找最近的服务器 package com.xl.ribbon.consumer.rules;import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractLoadBalancerRule; import com.netflix.loadbalancer.IRule; import com.netflix.loadbalancer.Server; import lombok.NoArgsConstructor; import org.springframework.util.CollectionUtils; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.servlet.mvc.condition.RequestConditionHolder;import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; import java.util.SortedMap; import java.util.TreeMap;NoArgsConstructor public class MyRule extends AbstractLoadBalancerRule implements IRule {Overridepublic void initWithNiwsConfig(IClientConfig iClientConfig) {}Overridepublic Server choose(Object key) {HttpServletRequest request ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();String uri request.getServletPath() ? request.getQueryString();return route(uri.hashCode(), getLoadBalancer().getAllServers());}public Server route(int hashId, ListServer servers) {if (CollectionUtils.isEmpty(servers)) {return null;}TreeMapLong, Server serverMap new TreeMap();servers.forEach(server - {// 虚化若干个服务节点到环上for (int i 0; i 8; i) {long hash hash(server.getId() i);serverMap.put(hash, server);}});long hash hash(String.valueOf(hashId));SortedMapLong, Server last serverMap.tailMap(hash);// 当request URL的hash值大于任意一个服务器对应的hashKey// 取serverMap中的第一个节点if (last.isEmpty()) {Server value serverMap.firstEntry().getValue();last.put(hash, value);}return last.get(last.firstKey());}public long hash(String key) {MessageDigest md5;try {md5 MessageDigest.getInstance(MD5);} catch (NoSuchAlgorithmException e) {throw new RuntimeException(e);}byte[] keyBytes null;try {keyBytes key.getBytes(UTF-8);} catch (UnsupportedEncodingException e) {throw new RuntimeException(e);}md5.update(keyBytes);byte[] digest md5.digest();long hash (digest[2] 0xFF 16) | (digest[1] 0xFF) 8 | (digest[0] 0xFF);return hash 0xffffffffL;} } 5、规则配置 其实直接配置在application.properties也可以这里我是在一个配置文件 package com.xl.ribbon.consumer;import com.netflix.loadbalancer.IRule; import com.netflix.loadbalancer.RandomRule; import com.xl.ribbon.consumer.rules.MyRule; import org.springframework.cloud.netflix.ribbon.RibbonClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** Created by lig on 2024/10/12.*/ Configuration //RibbonClient(name eureka-client, configuration com.netflix.loadbalancer.RandomRule.class) RibbonClient(name eureka-client, configuration MyRule.class) public class RibbonConfiguration { // // Bean // public IRule defaultLBStrategy() { // return new RandomRule(); // }} 6、接口 package com.xl.ribbon.consumer;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate;/*** Created by lig on 2024/10/12.*/ RestController public class RibbonController {Autowiredprivate RestTemplate restTemplate;GetMapping(/sayHi)public String sayHi() {return restTemplate.getForObject(http://eureka-client/sayHi, String.class);}} 总结 其实在实际项目中ribbon编写符合自己业务的规则还是挺复杂的用途还是挺广的.
http://www.w-s-a.com/news/444515/

相关文章:

  • 南宁做网站费用iis编辑网站绑定
  • 家用宽带做网站服务器建网站费用明细
  • 电商 网站 降低 跳出率 措施 效果书画院网站模板
  • 兰州移动官网网站建设上海工商网上公示系统
  • 在招聘网站里做电话销售免费空间可以上传网站吗
  • 梅州建站怎么做中国建设银行官网下载
  • 网站静态化设计广州网站备案方案
  • 西安网络技术有限公司网站扬中网站建设方案
  • 青海省教育厅门户网站wordpress core
  • idc科技公司网站模板蜜雪冰城网络营销案例分析
  • 微信与网站对接手机软件怎么做
  • 户县网站建设珠海专业制作网站
  • 麦当劳的网站优化建议猎头公司工作怎么样
  • 合肥地区网站制作网页浏览器打不开
  • 做网站的不给ftp网站如何做触屏滑动
  • wordpress statraq重庆百度优化
  • 企业网站官网英文WordPress站点切换为中文
  • 服装公司网站定位一点号自媒体平台
  • 密云微网站建设汽车之家手机官网首页
  • 多语言外贸网站制作苏州建设网站微信公众号
  • 用wordpress建站学什么百度给企业做网站吗
  • 福建城乡建设网站做数码测评的网站
  • 东海县建设局网站wordpress 好用的主题
  • 网站图片设计制作制作一个门户网站需要多少钱
  • 虚拟币交易网站源码自己给网站做支付接口
  • 免费的seo网站在线 crm
  • 绍兴市高速公路建设指挥部网站网站主页和子页风格如何统一
  • 获取网站状态网站租金可以做办公费吗
  • 网站开发执行什么标准号wordpress主题 表白
  • 杭州网站推广与优化凡科网是免费的吗