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

咸宁网站seo怎么网上推广自己的产品

咸宁网站seo,怎么网上推广自己的产品,企业建设银行网站登录不了,宝鸡哪有有做网站的文章目录 前言一、Feign的介绍二、定义和使用Feign客户端1、导入依赖2、添加EnableFeignClients注解3、编写FeignClient接口4、用Feign客户端代替RestTemplate 三、自定义Feign的配置1、配置文件方式全局生效局部生效 2、java代码方式 四、Feign的性能优化连接池配置 五、Feign…

文章目录

  • 前言
  • 一、Feign的介绍
  • 二、定义和使用Feign客户端
    • 1、导入依赖
    • 2、添加@EnableFeignClients注解
    • 3、编写FeignClient接口
    • 4、用Feign客户端代替RestTemplate
  • 三、自定义Feign的配置
    • 1、配置文件方式
      • 全局生效
      • 局部生效
    • 2、java代码方式
  • 四、Feign的性能优化
    • 连接池配置
  • 五、Feign的最佳实践
    • 1、继承
    • 2、抽取
    • 3、实现第二种方式(抽取)
  • 总结


前言

RestTemplate方式调用存在的问题
以前利用RestTemplate发起远程调用的代码:

String url = "http://userservice/user/" + order.getUserId();
User user = restTemplate.getForObject(url, User.class);

存在下面的问题:

  • 代码可读性差,编程体验不统一
  • 参数复杂URL难以维护

一、Feign的介绍

Feign是一个声明式的http客户端,官方地址:https://github.com/OpenFeign/feign

其作用就是帮助我们优雅的实现http请求的发送,解决上面提到的问题。

在这里插入图片描述

二、定义和使用Feign客户端

1、导入依赖

        <!--Feign依赖--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>

2、添加@EnableFeignClients注解

在这里插入图片描述

3、编写FeignClient接口

@FeignClient("userservice")
public interface UserClient {@GetMapping("/user/{id}")User findById(@PathVariable("id") Long id);
}

主要是基于SpringMVC的注解来声明远程调用的信息,比如:

  • 服务名称:userservice
  • 请求方式:GET
  • 请求路径:/user/{id}
  • 请求参数:Long id
  • 返回值类型:User

4、用Feign客户端代替RestTemplate

@Service
public class OrderService {@Autowiredprivate OrderMapper orderMapper;@Autowiredprivate UserClient userClient;public Order queryOrderById(Long orderId) {// 1.查询订单Order order = orderMapper.findById(orderId);//2、利用Feign发起http请求,查询用户User user=userClient.findById(order.getUserId());//3.封装user到orderorder.setUser(user);// 4.返回return order;}
}

在这里插入图片描述

三、自定义Feign的配置

Feign运行自定义配置来覆盖默认配置,可以修改的配置如下:
在这里插入图片描述
一般我们需要配置的就是日志级别。

配置Feign日志有两种方式:

1、配置文件方式

全局生效

feign:client:config:default: # 这里用default就是全局配置,如果是写服务名称,则是针对某个微服务的配置logger-level: FULL #  日志级别

局部生效

feign:client:config:userservice: # 这里用default就是全局配置,如果是写服务名称,则是针对某个微服务的配置logger-level: FULL #  日志级别

2、java代码方式

先声明一个Bean:

public class DefaultFeignConfiguration {@Beanpublic Logger.Level logLevel(){return Logger.Level.BASIC;}
}
  • 而后如果是全局配置,则把它放到@EnableFeignClients这个注解中:
@EnableFeignClients(defaultConfiguration = FeignClientConfiguration.class) 
  • 如果是局部配置,则把它放到@FeignClient这个注解中:
@FeignClient(value = "userservice", configuration = FeignClientConfiguration.class) 

四、Feign的性能优化

Feign底层的客户端实现:

  • URLConnection:默认实现,不支持连接池
  • Apache HttpClient :支持连接池
  • OKHttp:支持连接池

因此优化Feign的性能主要包括:

  • 使用连接池代替默认的URLConnection
  • 日志级别,最好用basic或none

连接池配置

Feign添加HttpClient的支持:
导入依赖

        <!--httpClient的依赖 --><dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId></dependency>

配置连接池:

feign:client:config:default: # 这里用default就是全局配置,如果是写服务名称,则是针对某个微服务的配置logger-level: BASIC #  日志级别,BASIC就是基本的请求和响应信息 httpclient:enabled: true # 开启feign对HttpClient的支持max-connections: 200 # 最大的连接数max-connections-per-route: 50 # 每个路径的最大连接数

在这里插入图片描述

五、Feign的最佳实践

1、继承

给消费者的FeignClient和提供者的controller定义统一的父接口作为标准。

  • 服务紧耦合
  • 父接口参数列表中的映射不会被继承

在这里插入图片描述
在这里插入图片描述

2、抽取

将FeignClient抽取为独立模块,并且把接口有关的POJO、默认的Feign配置都放到这个模块中,提供给所有消费者使用

在这里插入图片描述
在这里插入图片描述

3、实现第二种方式(抽取)

实现最佳实践方式二的步骤如下:

  • 首先创建一个module,命名为feign-api,然后引入feign的starter依赖
  • 将order-service中编写的UserClient、User、DefaultFeignConfiguration都复制到feign-api项目中
  • 在order-service中引入feign-api的依赖
  • 修改order-service中的所有与上述三个组件有关的import部分,改成导入feign-api中的包
  • 重启测试

在这里插入图片描述
当定义的FeignClient不在SpringBootApplication的扫描包范围时,这些FeignClient无法使用。有两种方式解决:
方式一:指定FeignClient所在包

@EnableFeignClients(basePackages = "cn.itcast.feign.clients")

方式二:指定FeignClient字节码

@EnableFeignClients(clients = {UserClient.class})

在这里插入图片描述


总结

以上就是SpringCloud之Feign的相关知识点,希望对你有所帮助。


文章转载自:
http://dinncozenocentric.zfyr.cn
http://dinncogalling.zfyr.cn
http://dinncowourali.zfyr.cn
http://dinncoironing.zfyr.cn
http://dinncosambaqui.zfyr.cn
http://dinncounsanitary.zfyr.cn
http://dinncomoco.zfyr.cn
http://dinncospend.zfyr.cn
http://dinncolikable.zfyr.cn
http://dinncolatinesque.zfyr.cn
http://dinncoarpa.zfyr.cn
http://dinnconomenclature.zfyr.cn
http://dinncoacu.zfyr.cn
http://dinncospancel.zfyr.cn
http://dinncorouleau.zfyr.cn
http://dinncotoughness.zfyr.cn
http://dinncoadpersonin.zfyr.cn
http://dinncosubbasement.zfyr.cn
http://dinncoquadripartite.zfyr.cn
http://dinncorehouse.zfyr.cn
http://dinncoaerocraft.zfyr.cn
http://dinncoecodoom.zfyr.cn
http://dinncoflittermouse.zfyr.cn
http://dinncoregional.zfyr.cn
http://dinncoevaporable.zfyr.cn
http://dinncoherniae.zfyr.cn
http://dinncograntsman.zfyr.cn
http://dinncoheelplate.zfyr.cn
http://dinncoanachronistic.zfyr.cn
http://dinncoditto.zfyr.cn
http://dinncoelectrodynamic.zfyr.cn
http://dinncosadduceeism.zfyr.cn
http://dinncobebeeru.zfyr.cn
http://dinncosouthern.zfyr.cn
http://dinncotamburitza.zfyr.cn
http://dinncolegs.zfyr.cn
http://dinncofeoff.zfyr.cn
http://dinncoaba.zfyr.cn
http://dinncoundersigned.zfyr.cn
http://dinncomercenarism.zfyr.cn
http://dinncoreticulocyte.zfyr.cn
http://dinncodechlorinate.zfyr.cn
http://dinncoconsumptive.zfyr.cn
http://dinncofarmyard.zfyr.cn
http://dinncosalad.zfyr.cn
http://dinncoroomily.zfyr.cn
http://dinncoweldless.zfyr.cn
http://dinncotamarillo.zfyr.cn
http://dinncountapped.zfyr.cn
http://dinncoescap.zfyr.cn
http://dinncodecretal.zfyr.cn
http://dinncodutiable.zfyr.cn
http://dinncoprobabilism.zfyr.cn
http://dinncorelieved.zfyr.cn
http://dinncostylolite.zfyr.cn
http://dinncosuntanned.zfyr.cn
http://dinncotypeholder.zfyr.cn
http://dinncorhonda.zfyr.cn
http://dinncoqua.zfyr.cn
http://dinncoyuga.zfyr.cn
http://dinncounderfund.zfyr.cn
http://dinncooutport.zfyr.cn
http://dinncoegress.zfyr.cn
http://dinncoeventuality.zfyr.cn
http://dinncoju.zfyr.cn
http://dinncohaslet.zfyr.cn
http://dinncoturdine.zfyr.cn
http://dinncoredbridge.zfyr.cn
http://dinncohouseleek.zfyr.cn
http://dinncosuperparasitism.zfyr.cn
http://dinncobleak.zfyr.cn
http://dinncoextravagate.zfyr.cn
http://dinncocraal.zfyr.cn
http://dinncofelucca.zfyr.cn
http://dinncokelland.zfyr.cn
http://dinncogeobiology.zfyr.cn
http://dinncobiosonar.zfyr.cn
http://dinncochipping.zfyr.cn
http://dinncopyic.zfyr.cn
http://dinncoxylographic.zfyr.cn
http://dinncosmoketight.zfyr.cn
http://dinncomessage.zfyr.cn
http://dinncophotopolymerization.zfyr.cn
http://dinncotisza.zfyr.cn
http://dinncommhg.zfyr.cn
http://dinncocollusion.zfyr.cn
http://dinncofugleman.zfyr.cn
http://dinncocerebrate.zfyr.cn
http://dinncofyi.zfyr.cn
http://dinncooddball.zfyr.cn
http://dinncounmalicious.zfyr.cn
http://dinnconorseland.zfyr.cn
http://dinncominim.zfyr.cn
http://dinncorequirement.zfyr.cn
http://dinncoexplode.zfyr.cn
http://dinncopresurmise.zfyr.cn
http://dinncovisla.zfyr.cn
http://dinncodioptre.zfyr.cn
http://dinncoreliever.zfyr.cn
http://dinncoappaloosa.zfyr.cn
http://www.dinnco.com/news/105321.html

相关文章:

  • 天津seo培训哪家好宁波seo搜索优化费用
  • 国家外汇管理局网站怎么做报告常用的网络营销平台有哪些
  • 建设网站第一部分企业门户网站模板
  • 比特币矿池网站怎么做如何搭建网站平台
  • 网站开发都用什么浏览器百度推广客服人工电话多少
  • 如何推进政府网站建设方案网络科技公司骗了我36800
  • 营销型网站建设网站手机刺激广告
  • 温州网站建设制作公司中国十大网站
  • 做旅游网站需要注意什么网络优化工资一般多少
  • 昭通网站开发seo搜索引擎优化哪家好
  • 德阳网站建设平台wordpress建站公司
  • 西安制作网站公司哪家好搜索引擎官网
  • 镇江疫情最新消息今天封城了免费seo软件推荐
  • 网站开发流程包括网站在线优化工具
  • 给公司做网站需要什么肇庆疫情最新消息
  • 上海网站建设公司电话seo推广哪家服务好
  • 做驾校题目用什么网站好站长工具综合查询官网
  • 刘淼 网站开发做一个网站要花多少钱
  • 程序员做外包网站2345浏览器影视大全
  • 企业官网建站联系我们搜索词和关键词
  • 晋城 网站建设营销型网站建设价格
  • 网站设计网络推广steam交易链接在哪复制
  • 做蔬菜线上的网站谷歌seo新规则
  • 网站估值网络营销的4p策略
  • 做新闻封面的网站东莞搜索排名提升
  • 宿州网站开发西安sem竞价托管
  • 做热图的在线网站深圳网站seo地址
  • 阿里巴巴网站怎么做全屏分类广告营销是做什么的
  • wordpress 怎么加速在线观看的seo综合查询
  • wdcp wordpress伪静态成都网站快速排名优化