日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hystrix Health Indicator及Metrics Stream

發布時間:2024/4/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hystrix Health Indicator及Metrics Stream 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Propagating the Security Context or using Spring Scopeshttps://cloud.spring.io/spring-cloud-static/Brixton.SR7/傳播安全上下文,使用Spring Security的上下文,或者使用Spring的Scope,Spring他有幾種Scope,有SessionScope,和RequestScope,還有其他的ScopeThe same thing applies if you are using @SessionScope or @RequestScope. You will know when you need to do this because of a runtime exception that says it can’t find the scoped context.如果你想要線程本地的上下文,去傳播到這個注解,我們這個@HystrixCommand,它會在線程池中執行HystrixCommand,直接使用這種注解,讓他使用不同的隔離策略If you want some thread local context to propagate into a @HystrixCommand the default declaration will not work because it executes the command in a thread pool (in case of timeouts). You can switch Hystrix to use the same thread as the caller using some configuration, or directly in the annotation, by asking it to use a different "Isolation Strategy". For example:@HystrixCommand(fallbackMethod = "stubMyService",commandProperties = {@HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")} )@HystrixProperty然后用"execution.isolation.strategy",SEMAPHORE信號量https://github.com/Netflix/Hystrix/wiki/Configuration第一個就是execution.isolation.strategy這個屬性表明哪一個隔離策略,這個方法去執行了隔離策略This property indicates which isolation strategy HystrixCommand.run() executes with, one of the following two choices:一個是Thread,一個是SEMAPHORETHREAD — it executes on a separate thread and concurrent requests are limited by the number of threads in the thread-poolSEMAPHORE — it executes on the calling thread and concurrent requests are limited by the semaphore count一個是線程,一個是信號量,如果你配置線程的話,他就會使用隔離的線程,如果你用信號量的話,它會用你請求的線程,并發的請求會被信號量所限制,那我們可能就要問了,那他這個默認是什么呢,默認是Thread,默認并且推薦的配置呢,默認并且推薦的是Thread,我們先來寫個demo吧The default, and the recommended setting, is to run HystrixCommands using thread isolation (THREAD) and HystrixObservableCommands using semaphore isolation (SEMAPHORE).@GetMapping("/movie/{id}")@HystrixCommand(fallbackMethod = "findByIdFallback", commandProperties = @HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE"))public User findById(@PathVariable Long id) {return this.restTemplate.getForObject("http://microservice-simple-provider-user/simple/" + id, User.class);}public User findByIdFallback(Long id) {User user = new User();user.setId(0L);return user;}這樣配就意味著在一個線程里運行,請求它是一個線程,@HystrixCommand它是一個隔離的線程,就這樣的區別,@SessionScope,Spring的Bean他有幾種Scope,這是@SessionScope,其實就等同于Scope里面的Session,acts as a shortcut for {@code @Scope("session")} with the default<p>In this context, <em>scope</em> means the lifecycle of an instance, such as {@code singleton}, {@code prototype}, and so forth. Scopes provided out of the box in Spring may be referred to using the {@code SCOPE_*} constants available in the {@link ConfigurableBeanFactory} and {@code WebApplicationContext} interfaces.他有singleton,prototype,還有sessionScope,requestScope,還有global session,就是application,如果你使用session scope和request scope,你會知道你什么時候需要這樣做,因為那個時候會報一個運行時異常,假如他找不到scope context,這個時候你可以配HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")你還可以把屬性設為true,你可以配置Hystrix并發的策略,Hystrix不允許多個線程的策略,不允許注冊多個并發策略,Spring Cloud會在SPRING的上下文查找實現,并且將它包裝到自己的插件中,https://cloud.spring.io/spring-cloud-netflix/reference/html/#netflix-eureka-client-starterYou also have the option to set the hystrix.shareSecurityContext property to true. Doing so auto-configures a Hystrix concurrency strategy plugin hook to transfer the SecurityContext from your main thread to the one used by the Hystrix command. Hystrix does not let multiple Hystrix concurrency strategy be registered so an extension mechanism is available by declaring your own HystrixConcurrencyStrategy as a Spring bean. Spring Cloud looks for your implementation within the Spring context and wrap it inside its own plugin.https://cloud.spring.io/spring-cloud-netflix/reference/html/#netflix-eureka-client-starterhttps://github.com/spring-cloud/spring-cloud-netflix/issues/1330FEIGN + OAUTH2 calls from another thread not propagating security #1330Hi there, checkout the reference doc on 1.2.0.M1. A new property hystrix.shareSecurityContext=true will auto configure an Hyxtrik hook that will propagate the security context to the thread of your Hystrix command. Let me know if it fits your need.你可以查看一下官方文檔,在1.2.0MineStone,里程碑,那時候還不是正式版本,有一個新的屬性,hystrix.shareSecurityContext=true它會自動配置Hystrix的一個鉤子,如果這個屬性滿足你這個需求,告訴我一下,什么叫SecurityContext呢,就是SpringSecurity的上下文,他就叫securityContext,https://github.com/spring-cloud/spring-cloud-netflix/issues/1336Hystrix shareSecurityContext is not working #1336Spring SecurityBTW, I don't see Spring Security Starter in your gradle. The hystrix.shareSecurityContext will be effective if Spring Security is present in the classpath. Share a sample project and I'll see if there is any means to adapt the mechanism specially for Spring Cloud OAuth without depending on Spring Security.正常是不要去配置,等到拋異常了再去配置 package com.learn.cloud.controller;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.RestController; import org.springframework.web.client.RestTemplate;import com.learn.cloud.entity.User; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;@RestController public class MovieController {@Autowiredprivate RestTemplate restTemplate;@GetMapping("/movie/{id}")@HystrixCommand(fallbackMethod = "findByIdFallback", commandProperties = @HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE"))public User findById(@PathVariable Long id) {return this.restTemplate.getForObject("http://microservice-simple-provider-user/simple/" + id, User.class);}public User findByIdFallback(Long id) {User user = new User();user.setId(0L);return user;}}

?

總結

以上是生活随笔為你收集整理的Hystrix Health Indicator及Metrics Stream的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。