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

宁波免费建网站百度广告联盟赚广告费

宁波免费建网站,百度广告联盟赚广告费,单页网站怎么制作,有没有专门做针织衫的网站服务提供者集群 既然SpringCloud的是微服务结构,那么对于同一种服务,当然不可能只有一个节点,需要部署多个节点 架构图如下: 由上可以看出存在多个同一种服务提供者(Service Provider) 搭建服务提供者集…

服务提供者集群

既然SpringCloud的是微服务结构,那么对于同一种服务,当然不可能只有一个节点,需要部署多个节点

架构图如下:

由上可以看出存在多个同一种服务提供者(Service Provider)

搭建服务提供者集群

1、参考:SpringCloud 快速入门搭建单机版的:Eureka Server、Service Provider、Service Consumer

2、根据支付模块服务提供者(test-springcloud-provider-payment8001),在父工程中,同样新建一个支付模块的服务提供者(test-springcloud-provider-payment8002)

服务8001与8002的配置中,除端口外,其他都相同,且spring.application.name应用名称必须相同,表明2个服务是同一种服务

服务8002配置文件如下:

 1 # 端口2 server:3   port: 80024 5 spring:6   application:7     name: cloud-payment-service8   #   数据源基本配置9   datasource:
10     driver-class-name: com.mysql.cj.jdbc.Driver
11     url: jdbc:mysql://localhost:3306/test_springcloud?allowPublicKeyRetrieval=true&useSSL=true
12     username: admin
13     password: 123456
14 
15 eureka:
16   client:
17     # 表示将自己注册进Eureka Server默认为true
18     register-with-eureka: true
19     # 是否从Eureka Server抓去已有的注册信息,默认是true
20     fetch-registry: true
21     # 设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
22     service-url:
23       defaultZone: http://localhost:8761/eureka
24 
25 mybatis:
26   mapperLocations: classpath:mapper/*Mapper.xml
27   # 所有entity别名类所在的包
28   type-aliases-pachage: com.test.springcloud.entities

View Code

3、重新启动项目,打开Eureka查看,发现有2个支付服务

4、使用订单模块消费者调用支付服务

消费者部分代码模块如下:

 1 @Configuration2 public class AppConfig {3 4     /**5      * 注入restTemplate,请用请求rest接口6      * @return7      */8     @Bean9     // 标注此注解后,RestTemplate就具有了客户端负载均衡能力
10     // 负载均衡技术依赖于的是Ribbon组件~
11     // RestTemplate都塞入一个loadBalancerInterceptor 让其具备有负载均衡的能力
12     @LoadBalanced
13     public RestTemplate restTemplate(){
14         return new RestTemplate();
15     }
16 }
17 
18 
19 @RestController
20 @Slf4j
21 public class OrderController {
22 
23     public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";
24 
25     @Autowired
26     private RestTemplate restTemplate;
27 
28     @GetMapping("/consumer/payment/get/{id}")
29     public CommonResult<Payment> getPayment(@PathVariable("id") Long id){
30         return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, CommonResult.class);
31     }
32 
33     ...
34 }

由上可以,通过配置向容器中注入了RestTemplate对象,而RestTemplate又被标注此@LoadBalanced注解后,RestTemplate就具有了客户端负载均衡能力,也就是说RestTemplate会轮流调用服务的各个节点,到达均衡的目的

5、测试调用,启动项目,使用地址:http://localhost:8000/consumer/payment/get/1,进行访问,可以看到已到达负载均衡的目的

服务发现Discovery

服务发现就是对于注册进eureka里面的微服务,可以通过服务发现获得该服务的信息

案例如下:

1、在微服务中使用@EnableDiscoveryClient注解,启用服务发现

 1 // Eureka客户端2 @EnableEurekaClient3 // 启用服务发现4 @EnableDiscoveryClient5 @SpringBootApplication6 public class PaymentMain8001 {7     public static void main(String[] args) {8         SpringApplication.run(PaymentMain8001.class, args);9     }
10 }

2、编辑Controller,启用服务发现之后,它会自动向容器注入DiscoveryClient(服务发现客户端)

通过调用DiscoveryClient的getServices方法,从注册中心获取服务列表

通过调用DiscoveryClient的getInstances方法,从注册中心获取服务实例集

 1 public class PaymentController {2 3     @Autowired4     private DiscoveryClient discoveryClient;5 6     @GetMapping(value = "/payment/discovery")7     public Object discovery(){8         // 获取服务列表9         List<String> services = discoveryClient.getServices();
10         for (String element : services) {
11             log.info("=====element:" + element);
12         }
13         
14         // 获取服务实例集
15         List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVICE");
16         for (ServiceInstance instance : instances) {
17             log.info("服务发现" + "\n"
18                     + "getServiceId === " + instance.getServiceId() + "\n"
19                     + "getHost === " + instance.getHost() + "\n"
20                     + "getPort === " + instance.getPort() + "\n"
21                     + "getUri === " + instance.getUri() );
22         }
23 
24         return  this.discoveryClient;
25     }
26 
27 } 

3、启用服务,使用地址:http://localhost:8001/payment/discovery,进行访问

页面结果:

后台日志:

由上可知,通过DiscoveryClient能获取到注册进eureka里面的微服务信息。


文章转载自:
http://cephalization.c7630.cn
http://simuland.c7630.cn
http://packager.c7630.cn
http://flagellated.c7630.cn
http://trifecta.c7630.cn
http://startle.c7630.cn
http://gear.c7630.cn
http://mailer.c7630.cn
http://clobberer.c7630.cn
http://darned.c7630.cn
http://feudary.c7630.cn
http://resurgence.c7630.cn
http://counteraccusation.c7630.cn
http://notly.c7630.cn
http://exoplasm.c7630.cn
http://phellem.c7630.cn
http://venereology.c7630.cn
http://chemisorb.c7630.cn
http://fanfold.c7630.cn
http://featherhead.c7630.cn
http://doorman.c7630.cn
http://lotiform.c7630.cn
http://blameworthy.c7630.cn
http://gluteal.c7630.cn
http://semiticist.c7630.cn
http://flirt.c7630.cn
http://tournois.c7630.cn
http://hypnotism.c7630.cn
http://euthanatize.c7630.cn
http://venturesomely.c7630.cn
http://hosel.c7630.cn
http://citrulline.c7630.cn
http://whoredom.c7630.cn
http://nard.c7630.cn
http://retroversion.c7630.cn
http://grade.c7630.cn
http://exultantly.c7630.cn
http://facp.c7630.cn
http://compactness.c7630.cn
http://ethnohistoric.c7630.cn
http://tithe.c7630.cn
http://attain.c7630.cn
http://peculation.c7630.cn
http://bullwhip.c7630.cn
http://cyberworld.c7630.cn
http://monolatry.c7630.cn
http://cutification.c7630.cn
http://disallowable.c7630.cn
http://semimat.c7630.cn
http://drapery.c7630.cn
http://ree.c7630.cn
http://electronarcosis.c7630.cn
http://humidity.c7630.cn
http://sarsa.c7630.cn
http://matchboard.c7630.cn
http://drumble.c7630.cn
http://boxhaul.c7630.cn
http://izzard.c7630.cn
http://hobo.c7630.cn
http://electrotypy.c7630.cn
http://propretor.c7630.cn
http://lentil.c7630.cn
http://beniseed.c7630.cn
http://scotograph.c7630.cn
http://exempla.c7630.cn
http://multinucleate.c7630.cn
http://diapedetic.c7630.cn
http://cembalist.c7630.cn
http://esmtp.c7630.cn
http://biloquilism.c7630.cn
http://sequestrant.c7630.cn
http://mipafox.c7630.cn
http://incisive.c7630.cn
http://sfa.c7630.cn
http://kibbutz.c7630.cn
http://gradienter.c7630.cn
http://factorize.c7630.cn
http://mucid.c7630.cn
http://censoriously.c7630.cn
http://antoninianus.c7630.cn
http://microbicide.c7630.cn
http://antarctic.c7630.cn
http://jungle.c7630.cn
http://milo.c7630.cn
http://uniramous.c7630.cn
http://mastocytoma.c7630.cn
http://michigan.c7630.cn
http://offcast.c7630.cn
http://tyrrhene.c7630.cn
http://nonhygroscopic.c7630.cn
http://pinealectomize.c7630.cn
http://tankard.c7630.cn
http://chimaerism.c7630.cn
http://dutchman.c7630.cn
http://indoctrinate.c7630.cn
http://bolar.c7630.cn
http://terrifically.c7630.cn
http://rimless.c7630.cn
http://rebloom.c7630.cn
http://poetic.c7630.cn
http://www.zhongyajixie.com/news/78204.html

相关文章:

  • 东营设计网站建设房地产十大营销手段
  • 什么是电子商务网站开发搜索引擎营销实训报告
  • 快速做网站前端的视频教程seo高级优化方法
  • 有一套源码做网站还差什么网络营销技能大赛优秀作品
  • 汉沽做网站推广软文发布平台
  • php网站开发百度云重庆seo网站系统
  • 做网站app需要多少钱网站seo标题是什么意思
  • 网站推广做百度还是360化妆品软文推广范文
  • 网站下拉菜单关键词密度
  • 舟山网站建设推广长沙优化官网服务
  • 市桥有经验的网站建设互联网推广广告
  • 个人网站开发意义关于校园推广的软文
  • 徐州网警seo公司排名
  • 中山网站建设文化策划书赛事资讯赛马资料
  • 南京模板网站建设拉新推广怎么快速拉人
  • 临沂网站建设首选浩瀚网络百度投放广告流程
  • 个人做网站开发指标公司软文代写
  • 什么是网站栏目标题免费网站软件
  • 用国外网站 图片做自媒体新闻发布稿
  • 南宁有名的seo费用杭州seo托管公司推荐
  • 中国建设银行行网站电商怎么做
  • 怎么做游戏和网站漏洞免费b站软件推广网站2023
  • 网站上的字体大小小学四年级摘抄新闻
  • 请人做网站十大经典事件营销案例
  • 乐清做网站建设seo指什么
  • 台湾云服务器去哪里买seo首页网站
  • 网络营销主要做什么淄博网站seo
  • seo网站基础建设长沙seo网站排名
  • 做农产品网站seo关键词排名优化技巧
  • 深圳网站建设代理商计算机培训机构排名