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

建网站需要哪些硬件受欢迎的做网站

建网站需要哪些硬件,受欢迎的做网站,住房建设厅官网,宽创国际的展馆设计案例RestTemplate、WebClient与HttpInterface SpringBoot中集成了很多轻量级的Http客户端 RestTemplate:普通开发WebClient:响应式编程开发HttpInterface:声明式编程 响应式编程介绍 响应式编程#xff08;Reactive Programming#xff09;是一种编程范式#xff0c;用于处理…RestTemplate、WebClient与HttpInterface SpringBoot中集成了很多轻量级的Http客户端 RestTemplate:普通开发WebClient:响应式编程开发HttpInterface:声明式编程 响应式编程介绍 响应式编程Reactive Programming是一种编程范式用于处理异步数据流和事件流。它基于观察者模式和函数式编程的概念通过使用流Stream或者事件Event来处理数据的变化和交互。 在响应式编程中数据流被看作是一个连续的时间序列程序可以订阅这个数据流并对数据的变化做出相应的处理。当数据发生变化时程序会自动更新相关的操作而无需手动干预。 响应式编程具有以下特点 响应式能够对数据流中的变化做出及时响应而无需手动触发。 异步能够处理异步操作如网络请求或用户交互。 延迟执行只有在真正需要结果时才会执行相关操作。 可组合性能够将多个操作组合在一起形成复杂的数据流处理逻辑。 错误处理能够处理异常和错误并提供相应的处理机制。 响应式编程在很多场景下都具有优势例如用户界面的响应性、数据流的处理和分析等。 RestTemplate与WebClient区别 RestTemplate采用同步阻塞的方式运行WebClient采用异步非阻塞的方式运行只用需要WebClient返会的结果时对应的方法才会执行 使用WebClient 引入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webflux/artifactId/dependency构建业务 Service public class CityServiceImpl implements CityService {Overridepublic MonoString query(String city) {WebClient webClient WebClient.create();MapString, String param new HashMap();param.put(city, 西安);return webClient.get().uri(https://wttr.in/{city}?langzh, param).accept(MediaType.ALL).retrieve().bodyToMono(String.class);} }package com.vmware.controller;import com.vmware.service.CityService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono;RequestMapping(/city) RestController public class CityController {Autowiredprivate CityService cityService;GetMapping(/{city})public MonoString city(PathVariable String city) throws InterruptedException {MonoString mono cityService.query(city);return query;} } 注意:mono对象被返回之前实际上接口处于未调用状态当返回后延时调用 HttpInterface 介绍:HttpInterfaces是由spring6.0引入的新的http调用方式通过声明接口的方式对http请求进行调用与传统硬编码的方法有所不同依赖于spring-boot-starter-webflux 基本使用 package com.vmware.service;import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.service.annotation.GetExchange; import reactor.core.publisher.Mono;public interface CityWebClientService {GetExchange(url https://wttr.in/{city}?langzh)MonoString getWeather(PathVariable String city); }Overridepublic MonoString queryByWebClient(String city) {WebClient client WebClient.builder().baseUrl(https://wttr.in).codecs(clientCodecConfigurer - {clientCodecConfigurer.defaultCodecs().maxInMemorySize(256 * 1024 * 1024);//修改默认的buffer大小}).build();//创建工厂HttpServiceProxyFactory factory HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();//创建代理对象CityWebClientService service factory.createClient(CityWebClientService.class);return service.getWeather(city);}工程化使用 将WebClient和HttpServiceProxyFactory使用配置类注入到容器中将对应的WebClient请求接口代理后注入到容器中在对应的业务中进行注入WebClient请求接口 package com.vmware.config;import com.vmware.service.CityWebClientService; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.support.WebClientAdapter; import org.springframework.web.service.invoker.HttpServiceProxyFactory;Configuration public class WebClientConfig {/*** apiNote 配置WebClient* return*/Beanpublic WebClient httpServiceProxyFactory() {return WebClient.builder().codecs(clientCodecConfigurer - {clientCodecConfigurer.defaultCodecs().maxInMemorySize(256 * 1024 * 1024);//修改默认的buffer大小}).build();}/*** apiNote 构建 HttpServiceProxyFactory* param client* return*/Beanpublic HttpServiceProxyFactory factory(WebClient client) {//创建工厂return HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();}/*** apiNote 代理HttpClient接口* param factory* return*/Beanpublic CityWebClientService cityWebClientService(HttpServiceProxyFactory factory) {return factory.createClient(CityWebClientService.class);} }package com.vmware.service.impl;import com.vmware.service.CityService; import com.vmware.service.CityWebClientService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.support.WebClientAdapter; import org.springframework.web.service.invoker.HttpServiceProxyFactory; import reactor.core.publisher.Mono;import java.util.HashMap; import java.util.Map;Service public class CityServiceImpl implements CityService {Autowiredprivate CityWebClientService cityWebClientService;Overridepublic MonoString queryByWebClient2(String city) {return cityWebClientService.getWeather(city);} }
http://www.pierceye.com/news/472735/

相关文章:

  • 做网批那个网站好校园网站界面建设
  • 免费网站建设php济南网站建设公司官网
  • 徐汇网站推广网络营销的四个特点
  • 简易做网站wordpress插件tag
  • 红酒 公司 网站建设青岛安装建设股份公司网站
  • 小米路由hd 做网站营销型网站策划 建设的考试题
  • 运河网站制作自主建站平台
  • 万网 网站建设合同最好的网站开发语言
  • 网站备案密码收不到典当 网站
  • 东莞网站建设推广服务网站建设开票单位
  • 贵港公司做网站东莞凤岗企业网站建设推广
  • 网站制作过程中碰到的问题微信怎么做链接推广产品
  • 做网站留后门是怎么回事视频网站开发需求分析
  • 关于做网站的了解点电子商务应用平台包括哪些
  • 垂直门户网站都有什么网站首页index.html
  • wordpress网站加载效果线上推销的方法
  • 网站都有什么语言杭州网络营销公司
  • 济南高新网站制作正规seo排名外包
  • 网站方案讲解技巧ppt的免费网站
  • 个人网站名称有哪些WordPress dux修改
  • 普法网站建设方案app制作开发公司怎么收费
  • 网站平台建设哪家公司好网站建设建站在线建站
  • 龙岗区住房和建设局在线网站网站如何做团购
  • 河南省建设监理协会网站证书查询wordpress 修改链接
  • 做网站业务员怎么样深圳福田最新新闻事件
  • 衡水商城网站建设外贸汽车配件做那个网站
  • 做网站的色彩搭配的小知识群艺馆网站建设方案
  • 深圳 汽车网站建设学习网站建设培训
  • 制作手机网站用什么软件唐山网站专业制作
  • 网站后台如何登陆互联网营销中心