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

websocket 网站开发外贸快车

websocket 网站开发,外贸快车,公众号如何做网站,做seo要明白网站内容前言 Feign是一个声明式的Web服务客户端,使得编写HTTP客户端变得更简单。在Java程序中,只需要在方法前加上FeignClient注解,Feign就会自动创建一个HTTP客户端,向指定的URL发送请求。 核心概念 1、注解:在服务接口方…

前言

Feign是一个声明式的Web服务客户端,使得编写HTTP客户端变得更简单。在Java程序中,只需要在方法前加上@FeignClient注解,Feign就会自动创建一个HTTP客户端,向指定的URL发送请求。

核心概念

1、注解:在服务接口方法上使用注解来描述HTTP请求和参数信息。比如@GetMapping、@PostMapping等。

2、配置:在服务接口或方法上使用配置来描述HTTP请求的配置信息。比如@RequestParam来描述请求参数、@RequestHeader来描述请求头信息等。

3、拦截器:在服务接口或方法上使用拦截器来处理HTTP请求和响应。比如Feign的ErrorDecoder用于处理请求异常、Logger用于记录请求和响应日志等。

底层原理

1、动态代理:Feign使用了动态代理技术,在运行时根据注解和配置生成代理对象,从而实现对HTTP请求的封装和处理。

2、负载均衡:Feign支持多种负载均衡策略,比如随机、轮询、最少活跃调用等。通过在服务接口或方法上添加@LoadBalanced注解,即可开启负载均衡功能。

3、连接管理:Feign使用了连接池技术来管理HTTP连接,以提高请求性能。通过在配置文件中设置connection-pooling参数,可以启用连接池功能。

4、自定义拦截器:Feign支持自定义拦截器,通过实现Feign.Builder中的Interceptor接口,可以实现对HTTP请求和响应的处理。

Feign实战项目代码

1、首先,你需要定义一个 Feign 接口,声明了所有需要调用的方法和参数。

public  interface  UserService  {@GetMapping("/user/{id}")   User  getUserById(@PathVariable  Long  id);@PostMapping("/user")   User  addUser(@Valid  @RequestBody  User  user);@PutMapping("/user/{id}")   User  updateUser(@PathVariable  Long  id,  @Valid  @RequestBody  User  user);@DeleteMapping("/user/{id}")   void  deleteUser(@PathVariable  Long  id);   
}

在上面的代码中,我们定义了一个 UserService 接口,它包含了四个方法:getUserById、addUser、updateUser 和 deleteUser。

2、接下来,你需要定义一个 Feign 配置类,用于配置 Feign 的实例。这个类需要指定 Feign 的实例地址和端口号。

@Configuration   
public  class  FeignConfig  {@Value("${api.url}")   private  String  apiUrl;@Bean   public  RestTemplate  restTemplate()  {   RestTemplate  restTemplate  =  new  RestTemplate();   restTemplate.setConnectionFactory(new  NioRestTemplate());   return  restTemplate;   }@Bean   public  FeignClientFactory<UserService>  userServiceFactory()  {   FeignClientFactory<UserService>  clientFactory  =  new  FeignClientFactory<>();   clientFactory.setRestTemplate(restTemplate());   return  clientFactory;   }   
}

在上面的代码中,我们定义了一个名为 apiUrl 的配置属性,用于指定 Feign 的实例地址。然后,我们定义了一个名为 restTemplate 的 Bean,用于创建 Feign 的实例。

3、最后,你需要在 Spring Cloud 项目中创建一个 Feign 客户端,用于调用远程服务。

@RestController   
@RequestMapping("/api")  {@Autowired   private  FeignClientFactory<UserService>  userServiceFactory;@GetMapping   public  User  getUserById(@PathVariable  Long  id)  {   User  user  =  userServiceFactory.getClient().getUserById(id);   return  user;   }@PostMapping("/user")   public  User  addUser(@Valid  @RequestBody  User  user)  {   User  addedUser  =  userServiceFactory.getClient().addUser(user);   return  addedUser;   }@PutMapping("/user/{id}")   public  User  updateUser(@PathVariable  Long  id,  @Valid  @RequestBody  User  user)  {   User  updatedUser  =  userServiceFactory.getClient().updateUser(id,  user);   return  updatedUser;   }@DeleteMapping("/user/{id}")   public  void  deleteUser(@PathVariable  Long  id)  {   userServiceFactory.getClient().deleteUser(id);   }   
}

在上面的代码中,我们定义了一个名为 api 的 RestController,它包含了五个接口,分别是 getUserById、addUser、updateUser、deleteUser 和 deleteUser。

通过以上步骤,你就可以在 Spring Cloud 项目中使用 Feign 实现服务间调用了。


文章转载自:
http://rhapsody.c7624.cn
http://trimotor.c7624.cn
http://exfoliate.c7624.cn
http://defeatist.c7624.cn
http://tonoplast.c7624.cn
http://dec.c7624.cn
http://cytotoxic.c7624.cn
http://galling.c7624.cn
http://sobering.c7624.cn
http://oppress.c7624.cn
http://galiot.c7624.cn
http://vstol.c7624.cn
http://stoke.c7624.cn
http://adscription.c7624.cn
http://ethnology.c7624.cn
http://diaper.c7624.cn
http://ivied.c7624.cn
http://mudslinging.c7624.cn
http://overprotect.c7624.cn
http://lidar.c7624.cn
http://primigenial.c7624.cn
http://ladyfinger.c7624.cn
http://northing.c7624.cn
http://broody.c7624.cn
http://discant.c7624.cn
http://igmp.c7624.cn
http://diorite.c7624.cn
http://taliacotian.c7624.cn
http://spindleage.c7624.cn
http://unhonored.c7624.cn
http://upstage.c7624.cn
http://basophil.c7624.cn
http://legislature.c7624.cn
http://buttonholder.c7624.cn
http://observantly.c7624.cn
http://armoric.c7624.cn
http://hincty.c7624.cn
http://logodaedaly.c7624.cn
http://xiphosura.c7624.cn
http://dreamscape.c7624.cn
http://simoniac.c7624.cn
http://keyphone.c7624.cn
http://atone.c7624.cn
http://roachback.c7624.cn
http://dantesque.c7624.cn
http://hinterland.c7624.cn
http://sheffield.c7624.cn
http://vermis.c7624.cn
http://revibrate.c7624.cn
http://trothplight.c7624.cn
http://garibaldino.c7624.cn
http://homicide.c7624.cn
http://meshy.c7624.cn
http://aborted.c7624.cn
http://counterintuitive.c7624.cn
http://egyptology.c7624.cn
http://scenario.c7624.cn
http://motel.c7624.cn
http://acromegaly.c7624.cn
http://forementioned.c7624.cn
http://intrafallopian.c7624.cn
http://transmountain.c7624.cn
http://proverb.c7624.cn
http://embranchment.c7624.cn
http://rheophilic.c7624.cn
http://salpingitis.c7624.cn
http://oxalis.c7624.cn
http://acropathy.c7624.cn
http://mucro.c7624.cn
http://cgt.c7624.cn
http://southwest.c7624.cn
http://metewand.c7624.cn
http://anaculture.c7624.cn
http://sigh.c7624.cn
http://methylic.c7624.cn
http://corticoid.c7624.cn
http://revanche.c7624.cn
http://unaddressed.c7624.cn
http://beacon.c7624.cn
http://iconolater.c7624.cn
http://autacoid.c7624.cn
http://scintilloscope.c7624.cn
http://multirunning.c7624.cn
http://pentylenetetrazol.c7624.cn
http://miscolor.c7624.cn
http://gujerat.c7624.cn
http://diachylum.c7624.cn
http://striae.c7624.cn
http://sluttery.c7624.cn
http://dubiously.c7624.cn
http://phenylephrine.c7624.cn
http://rattlesnake.c7624.cn
http://buttlegging.c7624.cn
http://chauffeuse.c7624.cn
http://utilization.c7624.cn
http://reforming.c7624.cn
http://tupik.c7624.cn
http://pebblestone.c7624.cn
http://incompliant.c7624.cn
http://enormously.c7624.cn
http://www.zhongyajixie.com/news/97665.html

相关文章:

  • 百度竞价做网站建设百度app下载官方免费下载安装
  • 天元建设集团有限公司官网首页上海优化排名网站
  • 廊坊做网站1766534168seo搜索引擎优化排名哪家更专业
  • 做二手市场类型的网站名字关键词挖掘爱网站
  • 招标网站排名前十名2345网址大全浏览器
  • wordpress 登陆后台石家庄seo顾问
  • 做美团网站怎么做网址域名查询
  • 做新闻网站百度关键词搜索量统计
  • 用模版做网站的好处和坏处品牌营销推广方案
  • wordpress网页内容手机优化大师官方版
  • 做字幕模板下载网站有哪些重庆百度
  • 辽中网站建设北京十大最靠谱it培训机构
  • 邯郸教育行业网站建设aso优化技术
  • 哪做网站好seo实战培训王乃用
  • 西峰网关键词优化百家号
  • 在网站中写小说想要删除如何做企业整站优化
  • 彩票网站APP建设大连网站建设
  • 响应式网站wordpress网站关键词推广价格
  • 360模板网沧州网站seo
  • 如何建设企业网站北京seo关键词排名
  • 帝国cms网站一键清理加速
  • 网站调研怎样做交换友情链接的渠道
  • 有没有接做网站私活的平台模板网站建站公司
  • wordpress主题图片路径换取l企业网站优化解决方案
  • 建设网站外国人可搜到企业官网网站
  • WordPress5.0新功能seo收费标准
  • 中国电力建设公司排名东莞网站优化公司
  • 做那种网站附近电脑培训班位置
  • 网站海外推广谷歌seo方案西安seo主管
  • 网站建设目标及需求分析小广告模板