Implement a custom HystrixPropertiesStrategy plugin

Add a custom HystrixPropertiesStrategy implementation where getCommandPropertiesCacheKey is overridden to return null so that HystrixPropertiesFactory will always generate a new HystrixCommandProperties for each new HystrixCommand instantiation.
Fascinating. Hurrah for json then.
On Oct 6, 2014 11:49 AM, "Lloyd" <notifications@github.com> wrote:

> In
> app/com/m3/octoparts/hystrix/KeyAndBuilderValuesHystrixPropertiesStrategy.scala:
>
> > +import com.fasterxml.jackson.databind.ObjectMapper
> > +import com.netflix.hystrix.{ HystrixCommandKey, HystrixCommandProperties }
> > +import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy
> > +
> > +/**
> > + * Custom [[HystrixPropertiesStrategy]] implementation
> > + */
> > +class KeyAndBuilderValuesHystrixPropertiesStrategy extends HystrixPropertiesStrategy {
> > +  private val mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
> > +
> > +  /**
> > +   * Overriden to return a [[String]] that is a combination of the commandKey name and a JSON string
> > +   * of the builder values
> > +   */
> > +  override def getCommandPropertiesCacheKey(commandKey: HystrixCommandKey, builder: HystrixCommandProperties.Setter): String =
> > +    s"${commandKey.name()}-${mapper.writeValueAsString(builder)}"
>
> Back with Scalameter benches :)
>
> [info] - execution.generating the properties anew.Test-0 measurements:
> [info]     (mean = 0.12 ms, ci = <0.10 ms, 0.14 ms>, significance = 1.0E-10)
>
> [info] - execution.generating the JSON cacheKey.Test-1 measurements:
> [info]     (mean = 0.04 ms, ci = <0.03 ms, 0.05 ms>, significance = 1.0E-10)
>
> So even with the use of reflection, generating the cachekey is still 3
> times faster than generating a fresh one through a call to new
> HystrixPropertiesCommandDefault, with a much narrower confidence interval
> to boot.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/m3dev/octoparts/pull/36/files#r18440259>.
>