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

网站建设和优化的好处杭州专业网站优化公司

网站建设和优化的好处,杭州专业网站优化公司,做网页的网站素材,网站建设的关于Spring Cloud Open Feign的介绍可以参考这两篇博客 OpenFeign服务接口调用 使用Feign作为服务消费者 本博客参考gitee开源项目代码,结合自己的理解,记录下微服务场景下的使用。Talk is cheap. Show me the code! 一、项目结构 这里使用…

关于Spring Cloud Open Feign的介绍可以参考这两篇博客
OpenFeign服务接口调用
使用Feign作为服务消费者
本博客参考gitee开源项目代码,结合自己的理解,记录下微服务场景下的使用。Talk is cheap. Show me the code!

一、项目结构

这里使用eureka作为注册中心,,person和equipment两个web服务作为业务中台,本例中会使用postman调用person服务,person服务中调用equipment服务。

registry -- 注册中心(当前采用eureka)
person -- 人员服务person-api -- 人员相关api提供, 包括 req, resp, service 等person-biz -- 人员相关服务接口具体实现, 依赖person-apiperson-provider -- 人员相关微服务启动类, 依赖person-biz
equipment -- 设备服务equipment-api -- 设备相关api提供, 包括 req, resp, service 等equipment-biz -- 设备相关服务接口具体实现, 依赖equipment-apiequipment-provider -- 设备相关微服务启动类, 依赖equipment-biz

在这里插入图片描述
源码下载地址,欢迎star!
springboot-openfeign

二、registry – 注册中心(当前采用eureka)

1、application.yml

server:port: 8001  # 该服务端口eureka:instance:hostname: registry  # eureka的实例名称client:registerWithEureka: false  # false表示当前项目不以客户端注册到服务中心(因为该项目本身就是注册中心)fetchRegistry: false  # false表示当前项目不需要从注册中心拉取服务配置(因为该项目本身就是注册中心)serviceUrl:defaultZone: http://localhost:8001/eureka/spring:application:name: server-registy  # 当前项目的实例名称(很重要)

2、核心pom.xml

<!-- 引入eureka-server依赖  --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId><version>2.1.3.RELEASE</version></dependency><!-- gson --><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.6.2</version></dependency>

3、主启动类RegistryApplication

@SpringBootApplication
@EnableEurekaServer
public class RegistryApplication {public static void main(String[] args) {SpringApplication.run(RegistryApplication.class, args);}
}

三、person – 人员服务

1、application.yml

server:port: 8002spring:application:name: person-providereureka:client:serviceUrl:defaultZone: http://localhost:8001/eureka/feign:httpclient:enabled: true

2、核心pom.xml

cloud-person-provider

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId><version>2.2.1.RELEASE</version>
</dependency>

cloud-person-biz

        <!-- 使用web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.2.1.RELEASE</version></dependency><!-- person-api --><dependency><groupId>tca</groupId><artifactId>cloud-person-api</artifactId><version>1.0.0</version></dependency><!-- equipment-api --><dependency><groupId>tca</groupId><artifactId>cloud-equipment-api</artifactId><version>1.0.0</version></dependency>

cloud-person-api

        <!-- openFeign --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>2.2.1.RELEASE</version></dependency>

3、PersonFeign和PersonController

@FeignClient(value = "person-provider")
public interface PersonFeign {/*** 根据id获取人员* @param personReq* @return*/@PostMapping("/person/get")PersonResp get(PersonReq personReq);
}@RestController
@RequestMapping(value = "/person")
@Slf4j
public class PersonController {@Autowiredprivate EquipmentFeign equipmentFeign;/*** 获取人员* @param personReq* @return*/@PostMapping("/get")public PersonResp get(@Validated @RequestBody PersonReq personReq) {PersonResp personResp = new PersonResp();personResp.setId(personReq.getId());personResp.setAge(30);personResp.setName("Messi");EquipmentReq equipmentReq = new EquipmentReq();equipmentReq.setId(personReq.getId());EquipmentResp equipmentResp = equipmentFeign.get(equipmentReq);log.info("equipmentResp = {}", equipmentResp);return personResp;}
}

4、项目结构

在这里插入图片描述

四、equipment – 设备服务

1、application.yml

server:port: 8003spring:application:name: equipment-providereureka:client:serviceUrl:defaultZone: http://localhost:8001/eureka/

2、核心pom.xml

cloud-equipment-api

        <!-- openFeign --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>2.2.1.RELEASE</version></dependency>

cloud-equipment-biz

<!-- 使用web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.2.1.RELEASE</version></dependency><!-- equipment-api --><dependency><groupId>tca</groupId><artifactId>cloud-equipment-api</artifactId><version>1.0.0</version></dependency><!-- person-api --><dependency><groupId>tca</groupId><artifactId>cloud-person-api</artifactId><version>1.0.0</version></dependency>

cloud-equipment-provider

       <dependency><groupId>tca</groupId><artifactId>cloud-equipment-biz</artifactId><version>1.0.0</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId><version>2.2.1.RELEASE</version></dependency>

3、EquipmentFeign和EquipmentController

@FeignClient(value = "equipment-provider")
public interface EquipmentFeign {/*** 根据id获取人员* @param equipmentReq* @return*/@PostMapping("/equipment/get")EquipmentResp get(EquipmentReq equipmentReq);
}
@RestController
@RequestMapping(value = "/equipment")
@Slf4j
public class EquipmentController {@Autowiredprivate PersonFeign personFeign;/*** 获取人员* @param equipmentReq* @return*/@PostMapping("/get")public EquipmentResp get(@Validated @RequestBody EquipmentReq equipmentReq) {EquipmentResp equipmentResp = new EquipmentResp();equipmentResp.setId(equipmentReq.getId());equipmentResp.setName("平板设备");return equipmentResp;}
}

4、项目结构

在这里插入图片描述

五、测试

分别启动这三个服务,
在这里插入图片描述
利用postman访问localhost:8002/person/get,其中body中id传不同参数进行测试
在这里插入图片描述
在这里插入图片描述
可以发现能够通过openfeign在微服务之间进行接口调用!

http://www.yayakq.cn/news/485324/

相关文章:

  • 优化方案官方网站建站总结报告
  • 河南秋实网站建设企业名录搜索
  • 沛县网站建设wordpress注册不发邮件
  • 合肥建设银行网站于都网站建设
  • 各大搜索引擎网站登录入口成都小程序制作工作室
  • 湖南建设厅网站首页丹棱网站建设
  • 骏域网站建设专家公共资源交易中心招标流程
  • 知名广州网站建设东莞外网搭建公司
  • 郑州市城市建设管理局网站网站怎么添加后台
  • 营销型网站 平台百度网盘资源分享
  • 外国高端网站能免费做网站
  • 旅游网站建设的技术可行性wordpress自动添加html后缀
  • 建app网站要多少钱域名解析查询站长工具
  • 类似于滴滴的网站商城建设如果启动浏览器就能直接打开一个常用的网站主页_要怎么做?
  • 郑州网站建设项目腾讯云怎么备案网站吗
  • 建立公司网站的好处淘宝客怎么做直播网站
  • 做亚马逊有哪些网站可以清货免费做网站可以一直用吗
  • 个人网站做商城会怎样网站做ddns解析
  • 第二章 网站建设何炅做的网站广告
  • 网站制作的一般步骤建设银行泰安培训中心官方网站
  • 如何选择锦州网站建设公众平台小程序
  • 做网站公司 晨旭东方科技画
  • 自己做的网站不备案不能访问吗建设网站和别人公司重名
  • 全屋定制设计网站推荐php连接wordpress数据库
  • 网站建设中中文模板女生学大数据好就业吗
  • 网站分为哪些部分怎么做微信网站
  • 网站建设重庆招聘wordpress仿模版
  • 企业网站建设包括哪些网站开发和报价方案
  • 网站建设超链接字体变色代码建立网站的链接结构有哪几种形式
  • 龙岩网站建设的软件网站打不开建设中哪的问题