$ mn create-app my-app --features netflix-hystrix
Micronaut Netflix
Integration between Micronaut and Netflix OSS
Version:
1 Introduction
This project features integrations between Netflix OSS and Micronaut.
Release History
-
Micronaut 1.3.0 Minimum Version
-
Upgrade to Hystrix 1.5.18
-
Upgrade to Ribbon 2.7.17
1.0.0
-
Initial Version
2 Hystrix Support
Using the CLI
If you are creating your project using the Micronaut CLI, supply the |
Netflix Hystrix is a fault tolerance library developed by the Netflix team and designed to improve resilience of inter process communication.
Micronaut features integration with Hystrix through the netflix-hystrix
module, which you can add to your build.gradle
or pom.xml
:
implementation("io.micronaut.configuration:micronaut-netflix-hystrix")
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-netflix-hystrix</artifactId>
</dependency>
Using the @HystrixCommand Annotation
With the above dependency declared you can annotate any method (including methods defined on @Client
interfaces) with the @HystrixCommand annotation and it will wrap the methods execution in a Hystrix command. For example:
@HystrixCommand
String hello(String name) {
return "Hello $name"
}
This works for reactive return types such as Flowable etc. as well and the reactive type will be wrapped in a HystrixObservableCommand .
|
The @HystrixCommand annotation also integrates with Micronauts support for Retry Advice and Fallbacks
For information on how to customize the Hystrix thread pool, group and properties see the javadoc for @HystrixCommand. |
Enabling Hystrix Stream & Dashboard
You can enable a Server Sent Event stream to feed into the Hystrix Dashboard by setting the hystrix.stream.enabled
setting to true
in application.yml
:
hystrix:
stream:
enabled: true
This exposes a /hystrix.stream
endpoint with the format the Hystrix Dashboard expects.
3 Ribbon Support
Using the CLI
If you are creating your project using the Micronaut CLI, supply the $ mn create-app my-app --features netflix-ribbon |
Netflix Ribbon is a inter-process communication library used at Netflix that has support for customizable load balancing strategies.
If you need more flexibility in how your application performs client-side load balancing then you may wish use Micronaut’s Netflix Ribbon support.
To add Ribbon support to your application add the netflix-ribbon
configuration to build.gradle
or pom.xml
:
implementation("io.micronaut.configuration:micronaut-netflix-ribbon")
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-netflix-ribbon</artifactId>
</dependency>
The LoadBalancer implementations will now be RibbonLoadBalancer instances.
Ribbon’s Configuration options can be set using the ribbon
namespace in configuration. For example in application.yml
:
ribbon:
VipAddress: test
ServerListRefreshInterval: 2000
Each discovered client can also be configured under ribbon.clients
. For example given a @Client(id = "hello-world")
you can configure Ribbon settings with:
ribbon:
clients:
hello-world:
VipAddress: test
ServerListRefreshInterval: 2000
By default Micronaut registers a DiscoveryClientServerList for each client that integrates Ribbon with Micronaut’s DiscoveryClient.
4 Repository
You can find the source code of this project in this repository: