netflix-hystrix-Simple Example

Source: Internet
Author: User

1 /**2 * Commandwithfallbackvianetwork.run Analog Remote call failed, fallbackvianetwork simulation needs to get old data from Redis over the network3  */4  Public classCommandwithfallbackvianetworkextendsHystrixcommand<string> {5     Private Final intID;6 7     protectedCommandwithfallbackvianetwork (intID) {8         //when Threadpoolkey is not set, Threadpoolkey defaults to Groupkey, and different threadpoolkey represent different thread pools. 9         //a group name for a hystrixcommand. This was used for grouping together commands such as for reporting, alerting, dashboards or team/library ownership.Ten         Super(Setter.withgroupkey (HystrixCommandGroupKey.Factory.asKey ("Remoteservicex")) One                 //a key to represent a hystrixcommand for monitoring, circuit-breakers, metrics publishing, caching and other such uses.  A. Andcommandkey (HystrixCommandKey.Factory.asKey ("Getvaluecommand")) - . Andcommandpropertiesdefaults (Hystrixcommandproperties.setter () - . Withexecutionisolationstrategy (HystrixCommandProperties.ExecutionIsolationStrategy.THREAD))) ; the          This. ID =ID; -     } -  - @Override +     protectedString Run () { -         //Remoteservicexclient.getvalue (ID); +         //analog Remote call failed A         Throw NewRuntimeException ("Force Failure for example"); at     } -  - @Override -     protectedString Getfallback () { -         return Newfallbackvianetwork (ID). Execute (); -     } in  -     Private Static classFallbackvianetworkextendsHystrixcommand<string> { to         Private Final intID; +         Private StaticMap<integer, string> memcacheclient =NewConcurrenthashmap<> ();//serves as a Redis cache and requires access to the network -  the          PublicFallbackvianetwork (intID) { *             //Groupkey is consistent with Commandwithfallbackvianetwork, $             Super(Setter.withgroupkey (HystrixCommandGroupKey.Factory.asKey ("Remoteservicex"))Panax Notoginseng. Andcommandkey (HystrixCommandKey.Factory.asKey ("Getvaluefallbackcommand")) -                     //Use a different threadpool for the fallback command the                     //So saturating the Remoteservicex pool won ' t prevent +                     //fallbacks from executing A. Andthreadpoolkey (HystrixThreadPoolKey.Factory.asKey ("Remoteservicexfallback"))); the              This. ID =ID; +         } -  $ @Override $         protectedString Run () { -             returnmemcacheclient.get (ID); -         } the  - @OverrideWuyi         protectedString Getfallback () { the             //The fallback also failed -             //So this fallback-of-a-fallback would Wu             //fail silently and return null -             return NULL; About         } $     } -}

netflix-hystrix-Simple Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.