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

教育网站制作公司网站开发公司兴田德润在那里

教育网站制作公司,网站开发公司兴田德润在那里,智联招聘官方网,安卓的应用开发一、前言 本篇主要是围绕着两个点,1、集成 Feign,2、分离feign接口层,独立服务; 还有一点就是上篇文章的服务 iot-channel、system-server 服务名称调整成为了 chain-iot-channel、chain-system二、搭建 chain-common 服务 pom.…

一、前言

本篇主要是围绕着两个点,1、集成 Feign,2、分离feign接口层,独立服务;
还有一点就是上篇文章的服务 iot-channel、system-server 服务名称调整成为了 chain-iot-channel、chain-system

二、搭建 chain-common 服务

pom.xml 
    <properties><!-- lombok --><lombok.version>1.18.26</lombok.version></properties><!-- Dependencies --><dependencies><!-- Lombok Dependency --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency></dependencies>
chain-common 项目暂时只是空项目

二、搭建 chain-starter/chain-feign-starter 服务

chain-starter
chain-starter 服务只是一个 pom 项目,主要作用是来包含一些启动服务,例如 chain-feign-starter 之类
chain-feign-starter
搭建这个服务的主要是目的是,后续会有很多服务会引用到 Feign 框架,如果在每个服务独立引用 Feign,在后续的升级版本或需要增加 Feign 的配置就会很麻烦,所以现在统一管理起来
    <dependencies><!-- feign 客户端 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency></dependencies>

三、chain-system、chain-iot-channel 集成 Feign

pom.xml 增加 Feign 引用
        <dependency><groupId>com.chain</groupId><artifactId>chain-feign-starter</artifactId><version>${chain.version}</version></dependency>

四、服务配置 Feign

1、启动服务增加注解
在 chain-system、chain-iot-channel 启动服务都增加 @EnableFeignClients 注解,开发Feign 客户端
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class IotChannelServeApp {public static void main(String[] args) {SpringApplication.run(IotChannelServeApp.class, args);}
}
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class SystemServerApp {public static void main(String[] args) {SpringApplication.run(SystemServerApp.class);}
}
2、chain-iot-channel 服务增加被调用接口
IotChannelInterface.java
@RestController
@RequestMapping(path = "/iot/channel/open/api")
public class IotChannelInterface {@Override@GetMapping(path = "/testIotChannelFeign")public String testIotChannelFeign() {return "test iot channel feign open api";}
}
3、chain-system 服务增加调用接口
SystemForIotChannelInterfaceClient.java
@FeignClient(name = "chain-iot-channel", url = "http://localhost:10020", path = "/iot/channel/open/api")
public interface SystemForIotChannelInterfaceClient  {@GetMapping(path = "/testIotChannelFeign")String testIotChannelFeign();
}
在这里需要注意一点的是,如果在 IotChannelInterface.java 中配置了@RequestMapping(path = "/iot/channel/open/api"),那么在 SystemForIotChannelInterfaceClient.java 中就需要增加 path = "/iot/channel/open/api" 配置
还有另一点就是如果单独使用 Feign,没有集成 Ribbon,那么就需要在 @FeignClient 注解中增加 url 配置项,因为没有 Ribbon 框架是无法实现负载均衡,那么 name 参数的配置,不会直接调用到服务的,只能增加 url 配置

五、独立 Feign 调用接口

1、增加 chain-open-api/chain-iot-channel-api 服务
chain-open-api
chain-open-api 和 chain-starter 服务一样,只是一个 pom 项目,主要作用是来包含项目中每个服务对应的 open api 项目
chain-iot-channel-api
pom.xml
    <dependencies><!-- 自定义 Feign --><dependency><groupId>com.chain</groupId><artifactId>chain-feign-starter</artifactId><version>${chain.version}</version></dependency></dependencies>
IotChannelInterfaceApi.java
public interface IotChannelInterfaceApi {/*** 测试 iot channel 服务是否可用** @return String*/@GetMapping(path = "/testIotChannelFeign")String testIotChannelFeign();
}
2、增加对 chain-iot-channel-api 的引用
chain-iot-channel\chain-system
pom.xml
        <dependency><groupId>com.chain</groupId><artifactId>chain-iot-channel-api</artifactId><version>${chain.version}</version></dependency>
3、改造IotChannelInterface.java、SystemForIotChannelInterfaceClient.java
IotChannelInterface.java、
@RestController
@RequestMapping(path = "/iot/channel/open/api")
public class IotChannelInterface implements IotChannelInterfaceApi {@Overridepublic String testIotChannelFeign() {return "test iot channel feign open api";}
}
SystemForIotChannelInterfaceClient.java
@FeignClient(name = "chain-iot-channel", url = "http://localhost:10020", path = "/iot/channel/open/api")
public interface SystemForIotChannelInterfaceClient extends IotChannelInterfaceApi {
}

最后附上项目结构图
在这里插入图片描述

http://www.sczhlp.com/news/107946/

相关文章:

  • 怎么建立自己的网站平台红酒企业网站建设
  • 网站没有内容 备案能成功吗佛山网站建设哪里好
  • 做物流网站找哪家好上海seo顾问推推蛙
  • 学校网站建设团队德州做网站最好的公司有哪些
  • wordpress怎样搭建网站网页美工设计教学设计
  • 河南郑州广告公司网站建设做网站千篇一律
  • 贵阳网站定制建设开发 首商网深圳市住房和保障局官网
  • 网站备案拍照是什么公司网站应达到的功能
  • 建个人网站能赚钱吗公主岭市住房和城乡建设局网站
  • 怎么做淘宝客导购网站做爰网站視屏
  • 怎样在阿里巴巴上做网站网站描述样本
  • 网站验证码出不来望野古诗拼音
  • 如何安装网站程序企业网站建设专业性体现在
  • 武威市建设厅网站如何备份网站数据库
  • 常见的网站开发软件有哪些60平米一居室装修价格
  • 快速提升网站关键词排名江门网站建设总部电话
  • 哪个网站可以查企业信息苏州工业园区一站式服务中心
  • WordPress更改网站地址wnmp搭建wordpress
  • 东莞网站推广渠道有哪些重庆免费建网站
  • 临沂制作网站企业Wordpress慢加内存还是带宽
  • 做博客网站如何盈利网站开发总出现出现404
  • 湖南住房和建设厅网站企业网站翻译
  • 做物流网站费用开源wordpress小程序源码
  • 常州建设网站公司哪个网站财经做的最好
  • 谷歌外贸建站南宁市兴宁区建设局网站
  • 黑色赚钱的网站ui培训学校哪家好
  • RSA 共模攻击
  • 网站关键词快速排名技术重庆网站建设公司建站模板
  • 厦门网站建设高级课程wordpress企业主题
  • 德阳企业网站建设昆明航空公司官方网站