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

进入江苏省住房和城乡建设厅网站怎么做谷歌收录的网站

进入江苏省住房和城乡建设厅网站,怎么做谷歌收录的网站,嵊州市住房和城乡建设局网站,十大免费模板网站概述 目的#xff1a;解决微服务调用问题。如何从微服务A调用微服务B提供的接口。 特性#xff1a; 声明式语法#xff0c;简化接口调用代码开发。像调用本地方法一样调用其他微服务中的接口。集成了Eureka服务发现#xff0c;可以从注册中心中发现微服务。集成了Spring…概述 目的解决微服务调用问题。如何从微服务A调用微服务B提供的接口。 特性 声明式语法简化接口调用代码开发。像调用本地方法一样调用其他微服务中的接口。集成了Eureka服务发现可以从注册中心中发现微服务。集成了Spring Cloud LoadBalancer提供客户端负载均衡。从调用发起方控制微服务调用的请求时间防止服务雪崩。 使用Feign进行微服务调用 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactId/dependency导入依赖 !-- springboot web start --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- 引入nacos 注册中心依赖 注册服务 --dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependencydependencygroupIdcom.qf/groupIdartifactIdcommon/artifactId/dependency!-- feign--dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactId/dependency!-- 引入nacos配置中心依赖 --dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-config/artifactId/dependency/dependenciesyml文件 spring:application:name: feign-demo #跟配置的前缀名字cloud:nacos:server-addr: 127.0.0.1:8848config:file-extension: yamlprofiles:active: dev #跟配置的后缀 设备名匹配 logging:level:com.qf.feignconsumer.feign.UserFeignClient: debug server:port: 9090 feign:client:config:default:# 建立连接的超时时间connectTimeout: 5000# 发送请求后等待接口响应结果的超时时间readTimeout: 3000创建FeignClient接口 package com.qf.feignconsumer.feign;import com.qf.common.entity.User; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*;import java.util.List;FeignClient(service-user) public interface UserFeignClient {/*** 注意如果少加了RequestParam会抛出如下异常* Caused by: java.lang.IllegalStateException: Method has too many Body parameters* param pagenum* param pagesize* return* throws InterruptedException*/GetMapping(/user/page)public ListUser getUserByPage(RequestParam(pagenum) Integer pagenum,RequestParam(pagesize)Integer pagesize) throws InterruptedException;GetMapping(/user/getall)public ListUser getAll();PostMapping(/user/update)public User updateUser(RequestBody User user);DeleteMapping(/user/delete/{id})public User deleteUser(PathVariable(id) Integer id);} 使用主启动类 package com.qf.feignconsumer;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients;SpringBootApplication EnableDiscoveryClient//注册到nacos中 EnableFeignClients//注意使用feign时 需要添加该注解 public class FeignApp9090 {public static void main(String[] args) {SpringApplication.run(FeignApp9090.class,args);} } FeignController package com.qf.feignconsumer.controller;import com.qf.common.entity.User; import com.qf.common.vo.ResultVo; import com.qf.feignconsumer.feign.ProviderFeigngClient; import com.qf.feignconsumer.feign.UserFeignClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;import java.util.List;RestController public class FeignController {AutowiredUserFeignClient userFeignClient;AutowiredProviderFeigngClient providerFeigngClient;GetMapping(/u/test4)public ResultVo utest4() throws InterruptedException {ListUser userByPage userFeignClient.getUserByPage(1, 2);return ResultVo.ok(1,ok,userByPage);}GetMapping(/echo)public ResultVo echo(String msg){String echo providerFeigngClient.echo(msg);return ResultVo.ok(1,asd,echo);}GetMapping(/u/test1)public ResultVo utest1(){//使用feignclient发起微服务用ListUser users userFeignClient.getAll();System.out.println(users);return ResultVo.ok(1,ok,users);}GetMapping(/u/test2)public ResultVo utest2(){//使用feignclient发起微服务用System.out.println(utest2);User user new User(100, luffy, 123);User user1 userFeignClient.updateUser(user);return ResultVo.ok(1,ok,user1);}GetMapping(/u/test3)public ResultVo utest3(){//使用feignclient发起微服务用System.out.println(utest3);User user1 userFeignClient.deleteUser(100);return ResultVo.ok(1,ok,user1);}} 日志配置类 package com.qf.feignconsumer.config;import feign.Logger; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class FeignConfig {Beanpublic Logger.Level liver(){/** NONE默认的不显示任何日志* BASIC仅记录请求方法、RUL、响应状态码及执行时间* HEADERS除了BASIC中定义的信息之外还有请求和响应的头信息* FULL除了HEADERS中定义的信息之外还有请求和响应的正文及元数据*/return Logger.Level.FULL;} } 提供服务方的controller package com.qf.userprovider.controller;import com.qf.common.entity.User; import org.springframework.web.bind.annotation.*;import java.util.Arrays; import java.util.List;RestController RequestMapping(/user) public class UserController {GetMapping(/page)public ListUser getUserByPage(RequestParam(pagenum) Integer pagenum,RequestParam(pagesize)Integer pagesize) throws InterruptedException {User user new User(1, zhangsan1, 1234567);User user2 new User(2, lisi, 12345);Thread.sleep(5000);ListUser users Arrays.asList(user, user2);return users;}GetMapping(/getall)public ListUser getAll(){User user1 new User(1, zhangsan, 12345677);User user2 new User(2, lisi, asdasdaas);ListUser users Arrays.asList(user1, user2);return users;}PostMapping(/update)public User updateUser(RequestBody User user){System.out.println(user);//根据id更新用户user.setPassword(88889888);return user;}DeleteMapping(/delete/{id})public User deleteUser(PathVariable(id) Integer id){System.out.println(要删除用户的idid);//去数据库里删除User luffy new User(id, luffy, 12345);return luffy;}} Feign负载均衡 注册中心中观察发现Micro1微服务在Eureka注册中心中有两个服务节点 当发起feign调用时究竟调用的是哪个节点呢 RestController RequestMapping(/user) public class UserController {Value(${server.port})String port;GetMapping(/findAll)ListUser findAll(){System.out.println(port);try {TimeUnit.SECONDS.sleep(10);} catch (InterruptedException e) {e.printStackTrace();}ListUser users Arrays.asList(new User(1,zhangsan, 123456, 29), new User(2,lisi, 12345, 19));return users;}}Feign使用的是轮询负载均衡算法当有多个节点时采用轮询的方式依次调用。 Feign调用超时时间设置 feign:client:config:default:# 建立连接的超时时间connectTimeout: 5000# 发送请求后等待接口响应结果的超时时间readTimeout: 10000将微服务的接口响应时间延长观察接口调用超时抛异常 GetMapping(/findAll)ListUser findAll(){System.out.println(port);try {TimeUnit.SECONDS.sleep(10);} catch (InterruptedException e) {e.printStackTrace();}ListUser users Arrays.asList(new User(1,zhangsan, 123456, 29), new User(2,lisi, 12345, 19));return users;}添加全局异常处理 RestControllerAdvice public class ExHandler {ExceptionHandler(Exception.class)public String handleEx(Exception e){return e.getMessage();}}Feign配置日志 添加一个配置类 Configuration public class FeignConfig {Beanpublic Logger.Level liver(){/** NONE默认的不显示任何日志* BASIC仅记录请求方法、RUL、响应状态码及执行时间* HEADERS除了BASIC中定义的信息之外还有请求和响应的头信息* FULL除了HEADERS中定义的信息之外还有请求和响应的正文及元数据*/return Logger.Level.FULL;} }yml文件中为FeignClient接口配置日志级别 logging:level:com.qf.feign.XXXClient: debug
http://wiki.neutronadmin.com/news/283957/

相关文章:

  • 如何建网站遂宁怎么做百度快照让网站排前面
  • 温州做网站建设公司建设网站为网站网站做广告
  • 微信微网站开发报价车轮违章查询是什么网站开发
  • CMS源码就可以做网站吗wordpress 用户api
  • 宝思哲手表网站免费软件电视剧最全
  • 免费的软件网站抖音代运营合作策划书
  • 深圳网站设计 工作室小程序商城开发平台
  • 怎样给网站或者商品做推广史先生 网站建设
  • 网站页面设计内容网站风格确认书
  • 电商扶贫网站建设手机排行榜前十名
  • 安阳网站建设价格丹阳官方网站建站
  • 备案期间怎么访问网站企业建立网站需要
  • wordpress站点前台请求数过多wordpress 外贸 开发
  • 酒店建设网站的意义超酷网站
  • 有没有代做模型的网站大数据营销精准营销
  • 杭州网站推广优化公司免费的短视频app大全下载
  • 游戏网站服务器租用淘词神器
  • 网站后台口令网页的后台管理系统
  • 泽成seo网站排名963中华室内设计网
  • 网站制作公司网站源码群晖wordpress性能
  • 制作网站建设的公司简单个人网站模板
  • 做本地分类信息网站赚钱吗图书网站开发介绍
  • 优秀企业网站欣赏wordpress 站内链接
  • 怎样给网站做国内网站建设的趋势是怎样的
  • 360搜索怎么做网站自然优化如何给网站增加内链
  • 如何在国外社交网站上做原单外贸大多数软件仍然是定制开发的
  • 手机端快速建站工具旅游公共信息服务网站建设及服务质量标准
  • html网站模板免费网站后台用什么开发
  • 网站解决方案设计企业网站建设费用入什么科目
  • 做电影网站涉及的侵权问题网站建设现在什么服务器比较好