ribbon-discovery-filter-spring-cloud-starter

Spring Cloud Netflix Ribbon Discovery Filter

License

License

Categories

Categories

Ribbon Net HTTP Clients
GroupId

GroupId

io.jmnarloch
ArtifactId

ArtifactId

ribbon-discovery-filter-spring-cloud-starter
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

ribbon-discovery-filter-spring-cloud-starter
Spring Cloud Netflix Ribbon Discovery Filter
Project URL

Project URL

https://github.com/jmnarloch/ribbon-discovery-filter-spring-cloud-starter
Source Code Management

Source Code Management

https://github.com/jmnarloch/ribbon-discovery-filter-spring-cloud-starter.git

Download ribbon-discovery-filter-spring-cloud-starter

How to add to project

<!-- https://jarcasting.com/artifacts/io.jmnarloch/ribbon-discovery-filter-spring-cloud-starter/ -->
<dependency>
    <groupId>io.jmnarloch</groupId>
    <artifactId>ribbon-discovery-filter-spring-cloud-starter</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.jmnarloch/ribbon-discovery-filter-spring-cloud-starter/
implementation 'io.jmnarloch:ribbon-discovery-filter-spring-cloud-starter:2.1.0'
// https://jarcasting.com/artifacts/io.jmnarloch/ribbon-discovery-filter-spring-cloud-starter/
implementation ("io.jmnarloch:ribbon-discovery-filter-spring-cloud-starter:2.1.0")
'io.jmnarloch:ribbon-discovery-filter-spring-cloud-starter:jar:2.1.0'
<dependency org="io.jmnarloch" name="ribbon-discovery-filter-spring-cloud-starter" rev="2.1.0">
  <artifact name="ribbon-discovery-filter-spring-cloud-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.jmnarloch', module='ribbon-discovery-filter-spring-cloud-starter', version='2.1.0')
)
libraryDependencies += "io.jmnarloch" % "ribbon-discovery-filter-spring-cloud-starter" % "2.1.0"
[io.jmnarloch/ribbon-discovery-filter-spring-cloud-starter "2.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-configuration-processor Optional jar 1.2.5.RELEASE
org.springframework.cloud : spring-cloud-starter-eureka jar 1.0.3.RELEASE
org.springframework.cloud : spring-cloud-starter-ribbon jar 1.0.3.RELEASE

test (4)

Group / Artifact Type Version
org.mockito : mockito-all jar 1.10.19
org.springframework.boot : spring-boot-starter-web jar 1.2.5.RELEASE
junit : junit jar 4.12
org.springframework.boot : spring-boot-starter-test jar 1.2.5.RELEASE

Project Modules

There are no modules declared in this project.

Spring Cloud Ribbon Discovery Server filter

A Spring Cloud Ribbon extension for filtering the server list.

Build Status Coverage Status

Features

Allows to specify the criteria based on which the Ribbon load balanced servers lists will be chosen during runtime. It will affect the list of servers provided for instance through Eureka and allow to filter them based on presence of specific settings.

Setup

Add the Spring Cloud starter to your project:

<dependency>
  <groupId>io.jmnarloch</groupId>
  <artifactId>ribbon-discovery-filter-spring-cloud-starter</artifactId>
  <version>2.1.0</version>
</dependency>

Usage

The extension specifies a custom Ribbon rule - DiscoveryEnabledRule an abstract class through which you can provide your own filtering logic, currently it's only implementation is MetadataAwareRule that match the specified attribute against the registered service instance metadata map. The API allows to specify the expected attributes through RibbonFilterContextHolder at runtime.

The extension defines the glue code to perform the server filtering, but it's up to specific use case how exactly this is going to be used.

Example:

Let's consider situation when you have deployed multiple versions of the same application (by branching your codebase) overtime and you deploy and run them in your system simultaneously. You need to route your versioned requests towards correct services. A simple approach would be to prefix the name of your service like for instance recommendations-v1.0 or recommendations-v1.1 etc. This is going to work, but does not provide a very flexible solution. A more general approach would be to facilitate the metadata associated with your discovery service and add logic for filtering the services.

eureka:
  instance:
    metadataMap:
      version: 1.1
      variant: A

To route the Ribbon request towards services with specific metadataMap entries you need to populate the thread bound RibbonFilterContext:

RibbonFilterContextHolder.getCurrentContext()
                .add("version", "1.1")
                .add("variant", "A");

You can place such code in your application logic or in some more convenient place like for instance RestTemplate's ClientHttpRequestInterceptor for more generic approaches.

You may also provide your own custom logic, the only requirement is to implement and register instance of DiscoveryEnabledRule in your Spring application context.

Limitations

Due to lack of proper abstraction in Spring Cloud, this extension is targeting only Netflix Eureka, it's not going to work if you will use Consul or Zookeeper as your Spring Cloud enabled discovery services.

Properties

You can disable the extension through ribbon.filter.metadata.enabled property.


ribbon.filter.metadata.enabled=true # true by default

License

Apache 2.0

Versions

Version
2.1.0
2.0.1
2.0.0
1.0.0