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

企业3合1网站建设价格武汉网站推广公司

企业3合1网站建设价格,武汉网站推广公司,如何设置网站服务器访问权限,门户网站建设目标😀前言 本篇博文是关于SpringCloud Eureka搭建会员中心服务提供方-集群,希望你能够喜欢 🏠个人主页:晨犀主页 🧑个人简介:大家好,我是晨犀,希望我的文章可以帮助到大家,您…

😀前言
本篇博文是关于SpringCloud Eureka搭建会员中心服务提供方-集群,希望你能够喜欢

🏠个人主页:晨犀主页
🧑个人简介:大家好,我是晨犀,希望我的文章可以帮助到大家,您的满意是我的动力😉😉

💕欢迎大家:这里是CSDN,我总结知识的地方,欢迎来到我的博客,感谢大家的观看🥰
如果文章有什么需要改进的地方还请大佬不吝赐教 先在此感谢啦😊

文章目录

  • SpringCloud Eureka 服务注册与发现
      • 搭建会员中心服务提供方-集群
        • 架构示意图
        • 创建member-service-provider-10002
        • 创建resources/application.yml
        • 修改主启动类名
        • 完成测试
        • 注意事项和细节
      • 配置服务消费端member-service-consumer-80 使用会员中心服务集群
        • 架构图
        • 修改MemberConsumerController.java
        • 修改CustomizationBean.
        • 为了看到测试效果,修改服务提供方
        • 完成测试
          • 启动eureka server 集群(目前2 台)
          • 启动member-service-consumer-80
        • 交替访问member 服务说明:
          • 包依赖配置图
      • 获取Eureka Server 服务注册信息-DiscoveryClient
        • 需求分析/图解
        • 代码实现
        • 测试
        • 注意事项和细节说明

SpringCloud Eureka 服务注册与发现

搭建会员中心服务提供方-集群

架构示意图

image-20230827094503045

创建member-service-provider-10002

  1. 参考member-service-provider-10000 来创建member-service-provider-10002 即可
  2. 创建好后, 使用member-service-provider-10000 的源码和配置替换member-service-provider-10002 生成的代码(不要到磁盘整体拷贝,会出现关联到member-service-provider-10000 的问题,很麻烦,可以创建好新项目的包,然后再拷贝对应包下的文件,就不会出问题)
  3. 提醒,拷贝时不要忘记拷贝resources/mapper/MemberMapper.xml 这些xxx.xml 文件

创建resources/application.yml

  1. 创建好application.yml
  2. 从member-service-provider-10000 拷贝application.yml 的内容
  3. 修改端口号即可
server:port: 10002

修改主启动类名

  1. 修改member-service-provider-10000 的主启动类为MemberProviderApplication10000
@SpringBootApplication
@EnableEurekaClient
public class MemberProviderApplication10000 {public static void main(String[] args) {SpringApplication.run(MemberProviderApplication10000.class, args);}
}
  1. 修改member-service-provider-10002 的主启动类为MemberProviderApplication10002
@SpringBootApplication
@EnableEurekaClient
public class MemberProviderApplication10002 {public static void main(String[] args) {SpringApplication.run(MemberProviderApplication10002.class, args);}
}

完成测试

启动eureka server 集群(目前2 台)
启动member-service-provider-10000
启动member-service-provider-10002
测试页面
浏览器输入: http://eureka9001.com:9001/

image-20230827095024136

浏览器输入: http://eureka9002.com:9002/

image-20230827095043875

注意事项和细节

  1. 因为member-service-provider-10000 和member-service-provider-10002 作为一个集群提供服务, 因此需要将spring.application.name 进行统一
  2. 这样消费方通过统一的别名进行负载均衡调用

配置服务消费端member-service-consumer-80 使用会员中心服务集群

架构图

image-20230827095148765

修改MemberConsumerController.java

   //定义member_service_provider_url 这是一个基础url地址//使用shift+ctrl+u 进行字母大小写的切换/*** 说明:* 1. MEMBER-SERVICE-PROVIDER 就是服务提供方[集群], 注册到Eureka Server 的名称* 2. 也就是服务提供方[集群]对外暴露的名称为 MEMBER-SERVICE-PROVIDER* 3. MEMBER-SERVICE-PROVIDER 目前有 两个 Availability Zones member-service-provider:10000*    还有一个 member-service-provider:10002*    需要增加一个注解@LoadBalanced 赋予 RestTemplate 负载均衡的能力,也就是会根据你的负载均衡算法*    来选择某个服务去访问, 默认是轮询算法, 当然我们也可以自己配置负载均衡算法*/public static final String MEMBER_SERVICE_PROVIDER_URL ="http://MEMBER-SERVICE-PROVIDER";

修改CustomizationBean.

@Configuration
public class CustomizationBean {@Bean@LoadBalancedpublic RestTemplate getRestTemplate() {return new RestTemplate();}
}

为了看到测试效果,修改服务提供方

  1. 在两个服务提供方的查询和添加返回结果处增加自己服务名称信息, 其它位置可参考加入
@GetMapping(value = "/member/get/{id}")
public Result getMemberById(@PathVariable("id") Long id) {Member member = memberService.queryMemberById(id);log.info("查询结果= " + member);if (member != null) {return Result.success("查询成功member-service-provider-10000", member);} else {return Result.error("402", "ID= " + id + " 不存在");}
}

完成测试

启动eureka server 集群(目前2 台)

​ 启动member-service-provider-10000
​ 启动member-service-provider-10002
​ 先测试: http://localhost:10000/member/get/1 和http://localhost:10002/member/get/1

http://localhost:10000/member/get/1

image-20230827103522399

http://localhost:10002/member/get/1

image-20230827103608420

启动member-service-consumer-80

​ 浏览器访问: http://localhost/member/consumer/get/1

image-20230827103650508

再次访问,会看到访问到不同的服务.

image-20230827103716243

交替访问member 服务说明:

  1. 注解@LoadBalanced 底层是Ribbon 支持算法。
  2. 2.Ribbon 和Eureka整合后consumer 直接调用服务而不用再关心地址和端口号,且该服务还有负载功能。
包依赖配置图

1.spring-cloud-starter-netflix-eureka-client 自带spring-cloud-starter-netflix-ribbon(如图)

image-20230827104018297

获取Eureka Server 服务注册信息-DiscoveryClient

需求分析/图解

  1. 先看需求分析示意图

image-20230827104057308

  1. 这里我们以服务消费方, 去获取Eureka Server 的服务注册信息为例讲解

image-20230827104125560

  1. 当然也可以在服务提供方获取Eureka Server 的服务注册信息

代码实现

  1. 所在模块member-service-consumer-80
  2. 修改com/my/springcloud/controller/MemberConsumerController.java
 @GetMapping("/member/consumer/discovery")public Object discovery() {List<String> services = discoveryClient.getServices();//遍历servicesfor (String service : services) {log.info("服务名={}",service);List<ServiceInstance> instances = discoveryClient.getInstances(service);for (ServiceInstance instance : instances) {log.info("id={},host={},port={},uri={}",instance.getServiceId(),instance.getHost(),instance.getPort(),instance.getUri());}}return discoveryClient;}
  1. 这里修改主启动类com/my/springcloud/MemberConsumerApplication.java
//排除DataSourceAutoConfiguration 自动配置
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
//@EnableEurekaClient 将该程序标识为EurekaClient
@EnableEurekaClient
//@EnableDiscoveryClient 注解启用服务发现
@EnableDiscoveryClient
public class MemberConsumerApplication {public static void main(String[] args) {SpringApplication.run(MemberConsumerApplication.class, args);}
}

测试

  1. 重启member-service-consumer-80
  2. 浏览器输出http://localhost/member/consumer/discovery

image-20230827104351757

后台信息:

image-20230827104419739

注意事项和细节说明

  1. 在引入DiscoveryClient 时,不要引入错误的包

    正确的包: import org.springframework.cloud.client.discovery.DiscoveryClient;
    错误的包: import com.netflix.discovery.DiscoveryClient;
    ​ 2.这里演示的是在服务消费方使用DiscoveryClient 来完成服务发现,同样,在服务提供方/模块也OK

文章到这里就结束了,如果有什么疑问的地方请指出,诸大佬们一起来评论区一起讨论😁
希望能和诸大佬们一起努力,今后我们一起观看感谢您的阅读🍻
如果帮助到您不妨3连支持一下,创造不易您们的支持是我的动力🤞


文章转载自:
http://dinncoelectromagnet.ydfr.cn
http://dinncoendurant.ydfr.cn
http://dinncobrooklime.ydfr.cn
http://dinncoverger.ydfr.cn
http://dinncoelectrodialysis.ydfr.cn
http://dinncoclasslist.ydfr.cn
http://dinncomegilp.ydfr.cn
http://dinncoindestructibility.ydfr.cn
http://dinncobimonthly.ydfr.cn
http://dinncoringtoss.ydfr.cn
http://dinncoraceabout.ydfr.cn
http://dinncolucency.ydfr.cn
http://dinncoorphan.ydfr.cn
http://dinncoacneigenic.ydfr.cn
http://dinncorezident.ydfr.cn
http://dinncobonsai.ydfr.cn
http://dinncocryostat.ydfr.cn
http://dinncomagnetoelasticity.ydfr.cn
http://dinncoteknonymy.ydfr.cn
http://dinncoparterre.ydfr.cn
http://dinncoaerobe.ydfr.cn
http://dinncowoken.ydfr.cn
http://dinncoschizoidia.ydfr.cn
http://dinncoodiousness.ydfr.cn
http://dinncokerygma.ydfr.cn
http://dinnconus.ydfr.cn
http://dinncoaplomb.ydfr.cn
http://dinncohalluces.ydfr.cn
http://dinncounderscore.ydfr.cn
http://dinncounsustained.ydfr.cn
http://dinncomerchantlike.ydfr.cn
http://dinncogigavolt.ydfr.cn
http://dinncohyperpietic.ydfr.cn
http://dinncolimpopo.ydfr.cn
http://dinncofanfaron.ydfr.cn
http://dinncorevehent.ydfr.cn
http://dinncoiata.ydfr.cn
http://dinncoamid.ydfr.cn
http://dinncooceanologist.ydfr.cn
http://dinncomammiferous.ydfr.cn
http://dinncobailout.ydfr.cn
http://dinncoskyward.ydfr.cn
http://dinncotearlet.ydfr.cn
http://dinncofigeater.ydfr.cn
http://dinncoplaylet.ydfr.cn
http://dinncoconsumerization.ydfr.cn
http://dinncooarless.ydfr.cn
http://dinncoegad.ydfr.cn
http://dinncoaristo.ydfr.cn
http://dinncoinsufficiently.ydfr.cn
http://dinncoinevitable.ydfr.cn
http://dinncoquemoy.ydfr.cn
http://dinncoextenuative.ydfr.cn
http://dinncopotstone.ydfr.cn
http://dinncoenantiomorphism.ydfr.cn
http://dinncoavascular.ydfr.cn
http://dinncoimpropriator.ydfr.cn
http://dinncofurbelow.ydfr.cn
http://dinncostratification.ydfr.cn
http://dinncotriticum.ydfr.cn
http://dinncoiridium.ydfr.cn
http://dinncosiffleuse.ydfr.cn
http://dinncocatabatic.ydfr.cn
http://dinncouncompensated.ydfr.cn
http://dinncopermanently.ydfr.cn
http://dinncodipody.ydfr.cn
http://dinncocontrecoup.ydfr.cn
http://dinncocystostomy.ydfr.cn
http://dinncodittany.ydfr.cn
http://dinncogreasiness.ydfr.cn
http://dinncoestablished.ydfr.cn
http://dinnconumbfish.ydfr.cn
http://dinncoscaup.ydfr.cn
http://dinncoisostructural.ydfr.cn
http://dinncoswipes.ydfr.cn
http://dinncoleprosarium.ydfr.cn
http://dinncoelectropositive.ydfr.cn
http://dinncolurch.ydfr.cn
http://dinncofervid.ydfr.cn
http://dinncoaiche.ydfr.cn
http://dinncocavea.ydfr.cn
http://dinncointerwind.ydfr.cn
http://dinncosteelworks.ydfr.cn
http://dinncoblastochyle.ydfr.cn
http://dinncoauxiliary.ydfr.cn
http://dinncofeather.ydfr.cn
http://dinncoerythrophilous.ydfr.cn
http://dinncocatboat.ydfr.cn
http://dinncoadultoid.ydfr.cn
http://dinncopotstone.ydfr.cn
http://dinncograined.ydfr.cn
http://dinncofranking.ydfr.cn
http://dinncocoastwaiter.ydfr.cn
http://dinncocaulocarpous.ydfr.cn
http://dinncoaganippe.ydfr.cn
http://dinncooptimal.ydfr.cn
http://dinncopaddy.ydfr.cn
http://dinncopickle.ydfr.cn
http://dinncorevolvable.ydfr.cn
http://dinncorepublish.ydfr.cn
http://www.dinnco.com/news/95743.html

相关文章:

  • 德州建设街小学网站如何在百度发布信息推广
  • 建网站需要什么操作系统网上竞价平台
  • 云服务器做网站新手教程seo网站推广seo
  • 做网站建设出路在哪里seo快速排名软件价格
  • 溧阳网站建设价格东莞关键词排名提升
  • 阳江房产网站浏览器观看b站视频的最佳设置
  • 武汉专业网站建设报价中国企业培训网
  • 网站建设 你真的懂吗公司网站页面设计
  • 个人怎么制作网站天津站内关键词优化
  • 草料二维码怎么制作网站whois查询 站长工具
  • 先做网站还是服务器北京seo顾问服务公司
  • 武汉网站建设知名公司排名永久免费制作网页
  • 网站制作 南宁营销方案ppt
  • 韩都衣舍网站建设seo什么意思简单来说
  • 咋做黄页网站seo研究中心vip课程
  • 馆陶县网站免费的网站申请
  • 阿里云 oss做网站东莞seo培训
  • 公司建设网站的费用吗个人seo怎么赚钱
  • 在潮州哪里找做网站的seo专员是干嘛的
  • vs网站中的轮播怎么做搜索引擎最新排名
  • 如何做企业网站推广西安网站建设
  • 网站建设开票税率如何搭建自己的网站
  • 做搜狗手机网站长尾郑州seo推广
  • 做网站都有哪些软件yy直播
  • 在线图片编辑尺寸大小标题优化怎样选关键词
  • 河北网站建设及推广百度账号登录中心
  • 网站做的好百度搜索排行榜风云榜
  • 企业网站建设 会计分录济南做网站公司
  • 响应式企业网站设计网站内搜索
  • seo技术推广培训苏州关键词优化seo