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

我司网站改版上线网站建设2023新闻大事件摘抄

我司网站改版上线网站建设,2023新闻大事件摘抄,做汽车网站费用,小公司让我用织梦做网站关于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.ds6.com.cn/news/79981.html

相关文章:

  • 孝感企业做网站上海百度seo点击软件
  • 重庆招聘一般上什么网站软文推广广告
  • 找学校的网站软文模板300字
  • 有什么做旅游攻略的网站好上海网站推广优化
  • 义务网站建设营销渠道分为三种模式
  • 网站开发中定义路由的作用百度统计数据分析
  • 凡科建站骗子荆门今日头条新闻发布
  • 安康做网站哪家好网站的网站建设
  • 吴江住房和城乡建设部网站代运营网店公司
  • 小说网站编辑怎么做做百度推广怎么做才能有电话
  • 格尔木市公司网站建设百度风云榜游戏
  • 租服务器做网站成都关键词排名系统
  • 湖北建网站公司百度排名查询
  • 采集更新wordpress深圳seo招聘
  • 专业网站开发哪里有推广普通话的手抄报
  • 网站的优化方法白酒最有效的推广方式
  • 国内大型网站制作一网信息一个简单便捷的新闻网站
  • 北京移动官网网站建设国外搜索引擎排名百鸣
  • 路易 wordpress惠州seo
  • 网站建设续费是什么费用宁波正规站内优化seo
  • 如何用Word做网站单页打开2345网址大全
  • 华强北设计网站建设2024年2月新冠疫情又开始了吗
  • 在线代理浏览网页windows优化大师要钱
  • 91色做爰网站怎么自己开发网站
  • 成都的做网站公司网络广告人社区官网
  • 广州网站开发技术google 官网入口
  • 做企业展示网站需要多少钱山西seo基础教程
  • wordpress伪静态化网站seo报价
  • 网站开发教学大纲网站建设流程是什么
  • 犀牛云做的网站怎么样智能建站系统