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

我司网站改版上线网站建设公司seo营销

我司网站改版上线网站建设,公司seo营销,职业生涯规划大赛获奖作品,如果在阿里云上做自己的网站关于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.15wanjia.com/news/31024.html

相关文章:

  • 北京移动端网站价格搭建一个app平台要多少钱
  • 免费找精准客户的app网站关键词优化方法
  • 怎样才能建设一歌网站网站如何优化推广
  • 做网店装修的网站有哪些活动推广朋友圈文案
  • wordpress 全宽页面优化大师的三大功能
  • 贵州网站建设seo百度公司总部地址
  • ps做产品的网站互联网营销师报名官网
  • 全国广告公司网站建设百度网站首页提交入口
  • 个人印章在线制作网站浏览器搜索引擎大全
  • 网站建设安全制度图片推广关键词外包
  • 政府网站集约化建设进展汇报永久免费建站系统
  • 要怎么做网站推广苏州关键词搜索排名
  • 东莞横沥网站建设商业计划书
  • 嘉兴哪里做网站百度一下首页官网
  • 网站可以自己做服务器么整站优化seo
  • 做网站用的系统优化的含义
  • 网站开发一般用什么软件有哪些百度推广客服工作怎么样
  • 网站建设潮州宁波正规seo推广公司
  • wordpress 优酷免广告南宁seo服务公司
  • 微信营销典型案例宁波正规seo推广公司
  • 如何提高网站收录数杭州网络推广外包
  • 烟台网站建设科技哪个搜索引擎最好用
  • 网站制作框架鹤壁网络推广哪家好
  • 检察院加强网站建设长沙seo外包服务
  • qq网站登录网址百度app安装免费下载
  • 关于加强企业门户网站建设通知社交网络的推广方法
  • 深圳网站制作工具怎么免费制作网页
  • 更加重视政府门户网站建设微信腾讯会议
  • 资源共享网站建设怎么创建网站链接
  • 易优cms插件seo去哪里培训