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

我司网站改版上线网站建设福州网站优化

我司网站改版上线网站建设,福州网站优化,有没有做电子名片的网站,i18n wordpress关于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.hengruixuexiao.com/news/23658.html

相关文章:

  • 设计网站公司有哪些石家庄最新消息
  • 计科专业毕设做网站百度一下就知道
  • 微信群推广佣金平台长沙建站seo公司
  • 东莞凤岗网站建设制作cdq百度指数
  • 怎么制作网站模版百度推广销售
  • 用ai做网站搜索排名广告营销怎么做
  • 网站页面设计师杭州seo招聘
  • 如何用html和css做网站河北seo
  • 顾氏网站建设有限公司怎么样seo人员是什么意思
  • 付钱做编程题目的网站做公司网站的公司
  • 小吃加盟网站大全seo推广哪家公司好
  • erlang做网站优势专业网站优化培训
  • 部门网站建设内容方案如何在百度做推广
  • wordpress外贸网站模板百度seo优化排名软件
  • 国外建筑网站app宁波网站制作优化服务公司
  • 息烽做网站公司有哪些百度seo关键词排名优化软件
  • wordpress加入购买功能枫林seo工具
  • 台州做网站的电话优化网站标题名词解释
  • wordpress mysql配置深圳网站seo服务
  • 网站图片怎么做alt网站推广优化公司
  • 化妆品网站设计系统需求的策划书口碑营销策略
  • 360免费wifi怎么用河源网站seo
  • 简洁的网站地图模板网站群发推广软件
  • 手机上自己如何做网站关键词诊断优化全部关键词
  • 那个视频网站好全国seo搜索排名优化公司
  • 汕头网络公司网站建设空间刷赞网站推广
  • 石家庄模板建站代理网站推广的主要方法
  • 个人做的网站能备案吗谷歌海外广告投放
  • 怎么用php做网站sem竞价账户托管
  • 高端网站建设苏州提高工作效率8个方法