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

网站的引导页面是什么意思最好旅游网站建设

网站的引导页面是什么意思,最好旅游网站建设,牛人网络网站,深圳卫生人才网官网Spring的WebClient提供了一个非阻塞客户端来进行服务调用。 Hystrix虽然现在处于维护模式#xff0c;但已通过防止级联故障#xff0c;为慢速或故障上游服务的呼叫提供断路器来保护服务对服务的呼叫。 在本文中#xff0c;我将探讨Spring Cloud如何提供一种更新的功能方法但已通过防止级联故障为慢速或故障上游服务的呼叫提供断路器来保护服务对服务的呼叫。 在本文中我将探讨Spring Cloud如何提供一种更新的功能方法以使用Hystrix封装远程调用。 考虑一个简单的服务该服务返回使用实体Wiremock工具建模的实体列表例如城市列表 WIREMOCK_SERVER.stubFor(WireMock.get(WireMock.urlMatching( /cities )) .withHeader( Accept , WireMock.equalTo( application/json )) .willReturn(WireMock.aResponse() .withStatus(HttpStatus.OK.value()) .withFixedDelay( 5000 ) .withHeader( Content-Type , application/json ))) 当使用类型为“ / cities”的uri进行调用时此Wiremock终结点将使用以下类型的json进行响应 [ { country : USA , id : 1 , name : Portland , pop : 1600000 }, { country : USA , id : 2 , name : Seattle , pop : 3200000 }, { country : USA , id : 3 , name : SFO , pop : 6400000 } ] 延迟5秒后。 传统方法 使用Hystrix的方法有很多传统上我倾向于使用显式的Hystrix Command保护远程调用的方法具体如下 import com.netflix.hystrix.HystrixCommandGroupKey import com.netflix.hystrix.HystrixCommandKey import com.netflix.hystrix.HystrixCommandProperties import com.netflix.hystrix.HystrixObservableCommand import org.bk.samples.model.City import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.MediaType import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.bodyToFlux import org.springframework.web.util.UriComponentsBuilder import reactor.core.publisher.Flux import rx.Observable import rx.RxReactiveStreams import rx.schedulers.Schedulers import java.net.URI CitiesHystrixCommand( class CitiesHystrixCommand( private val webClientBuilder: WebClient.Builder, private val citiesBaseUrl: String ) : HystrixObservableCommandCity( HystrixObservableCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey( cities-service .withGroupKey(HystrixCommandGroupKey.Factory.asKey( cities-service )) .andCommandKey(HystrixCommandKey.Factory.asKey( cities-service .andCommandKey(HystrixCommandKey.Factory.asKey( cities-service )) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds( 4000 ))) { override fun construct(): ObservableCity { val buildUri: URI UriComponentsBuilder .fromUriString(citiesBaseUrl) .path( /cities ) .build() .encode() .toUri() val webClient: WebClient this .webClientBuilder.build() val result: FluxCity webClient.get() .uri(buildUri) .accept(MediaType.APPLICATION_JSON) .exchange() .flatMapMany { clientResponse - clientResponse.bodyToFluxCity() } return RxReactiveStreams.toObservable(result) } override fun resumeWithFallback(): ObservableCity { LOGGER.error( Falling back on cities call , executionException) LOGGER.error( , executionException) return Observable.empty() } companion object { private val LOGGER: Logger LoggerFactory.getLogger(CitiesHystrixCommand:: class .java) } } 现在可以使用以下代码通过以下方式进行远程调用 import org.springframework.http.MediaType import org.springframework.web.reactive.function.client.WebClient class CitiesHystrixCommandBasedClient( private val webClientBuilder: WebClient.Builder, private val citiesBaseUrl: String ) { fun getCities(): FluxCity { val citiesObservable: ObservableCity CitiesHystrixCommand(webClientBuilder, citiesBaseUrl) .observe() .subscribeOn(Schedulers.io()) return Flux .from(RxReactiveStreams .toPublisher(citiesObservable)) } } 这里要注意两件事 1. WebClient返回代表城市列表的Project Reactor“ Flux”类型 但是Hystrix 基于Rx-Java 1 因此使用RxJavaReactiveStreams 提供的 “ RxReactiveStreams.toObservable”调用将Flux转换为Rx-Java Observable。 这里的图书馆 。 2.我仍然希望在应用程序的其余部分中使用Project Reactor“ Flux”类型因此还有另一个适配器将Rx-Java Observable转换回Flux“ Flux.fromRxReactiveStreams.toPublishercitiesObservable”一旦包装在Hystrix中的呼叫返回。 如果我尝试使用5秒钟延迟的Wiremock样本尝试此客户端则它将正确处理延迟并在一秒钟后返回。 功能方法 使用HystrixCommands的新功能性方法可以避免使用以前方法的许多样板该功能性方法是Spring Cloud附带的实用程序类它提供了使用Hystrix进行远程调用的功能性方法。 使用HystrixCommands进行的整个调用如下所示 import com.netflix.hystrix.HystrixCommandProperties import org.bk.samples.model.City import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.cloud.netflix.hystrix.HystrixCommands import org.springframework.http.MediaType import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.bodyToFlux import org.springframework.web.util.UriComponentsBuilder import reactor.core.publisher.Flux import rx.schedulers.Schedulers import java.net.URI class CitiesFunctionalHystrixClient( private val webClientBuilder: WebClient.Builder, private val citiesBaseUrl: String ) { fun getCities(): FluxCity { return HystrixCommands .from(callCitiesService()) .commandName( cities-service ) .groupName( cities-service ) .commandProperties( HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds( 1000 ) ) .toObservable { obs - obs.observe() .subscribeOn(Schedulers.io()) } .fallback { t: Throwable - LOGGER.error(t.message, t) Flux.empty() } .toFlux() } fun callCitiesService(): FluxCity { val buildUri: URI UriComponentsBuilder .fromUriString(citiesBaseUrl) .path( /cities ) .build() .encode() .toUri() val webClient: WebClient this .webClientBuilder.build() return webClient.get() .uri(buildUri) .accept(MediaType.APPLICATION_JSON) .exchange() .flatMapMany { clientResponse - clientResponse.bodyToFluxCity() } } companion object { private val LOGGER: Logger LoggerFactory.getLogger(CitiesHystrixCommand:: class .java) } } 这种方法避免了很多样板– 1.不再需要显式命令 2.通话和后备均以流畅的方式编码 3.可以明确指定任何替代–在此特定情况下超时时间为1秒。 结论 我喜欢HystrixCommands带给WebClient使用Hystrix的简洁性。 我的github仓库中提供了整个示例– https://github.com/bijukunjummen/webclient-hystrix-sample使这些示例正常工作所需的所有依赖项都属于此仓库。 如果您对使用Rx-Java 1感兴趣那么可以介绍一种方法 在这里可以帮助您避免使用香草Hystrix 翻译自: https://www.javacodegeeks.com/2019/05/functional-hystrix-using-spring-cloud-hystrixcommands.html
http://www.zqtcl.cn/news/390244/

相关文章:

  • 重庆企业网站的推广电力建设集团网站
  • 长沙制作网站词条有哪些网站可以做
  • 网站 网页区别简单的网页设计作品
  • 济南做网站推广有哪些公司天津建设工程信息网官方
  • 番禺市桥网站建设有关网站建设的知识
  • 信用中国 网站 支持建设怎么做网站美工
  • 做网站怎么样引流郑州最好的妇科医院排行
  • 云软件网站建设做仓单的网站
  • 邯郸做移动网站报价注册公司流程流程图
  • linux部署wordpress福州短视频seo推荐
  • 做地推的网站做网站感觉挣不到钱啊
  • 网站建设公司哪家好 搜搜磐石网络营销网站建设免费
  • 如何改网站的内容源码买卖网站
  • 企业网站 报价免费创意字体设计
  • 调用百度地图做全景的网站网站维护要求
  • 济宁网上做科目一的网站网站维护工程师薪酬
  • 领先的响应式网站建设平台湖北企业建站系统信息
  • 嘉兴市住房和城乡建设局网站巩义网站建设方案报价
  • 桂林做网站的公司哪家最好长沙网络工程学院
  • 广州 天河网站设计wordpress评论开关
  • 河南郑州建设网站做贺卡网站
  • 我的家乡湛江网站设计烟台网站建设招聘
  • 如何做网站改版评析网站建设报价单
  • 有关天猫网站开发的论文热狗seo顾问
  • 西安成品网站建设云主机建网站教程
  • 网站后台是怎么更新电商网站开发需求文档
  • 教人怎么做网页的网站有关建设网站的问题
  • wordpress资源站源码网站规划与建设课设报告
  • 网站后台ftp账户企企业业网网站站建建设设
  • 网站建设公司专业的建站优化公司成都天府新区网站建设