Code Monkey home page Code Monkey logo

ribbon-discovery-filter-spring-cloud-starter's Introduction

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

ribbon-discovery-filter-spring-cloud-starter's People

Contributors

jmnarloch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ribbon-discovery-filter-spring-cloud-starter's Issues

How to clear CurrentContext?

how to clean current context when add param into context
RibbonFilterContextHolder.getCurrentContext() .add("version", "1.1") .add("variant", "A");

[Question]

How to achieve session stickyness using ribbon with Zuul ? is this api support it ?

Issue with Zuul integration

Hello,

I tried to use your project with Zuul.
However, I have a problem.
This is my scenario :

  • Get to service A : /test1/
  • Get to service B : /test2/
  • Get to service A : /test1/ => Bad request, zuul redirects my request to service B.

Indeed, the LoadBalancer set into the rules doesn't contains any reference to my service A after the call to the service B. It's erased by com.netflix.loadbalancer.BaseLoadBalancer:360
this.rule.setLoadBalancer(this);

In the usually case, the rule is instanciated for each service, but in my case, it's defined by RibbonDiscoveryRuleAutoConfiguration class.
this.rule = new RoundRobinRule()

Do you have an idea to fix this problem ?

Thanks.

filter for multi value field

What if i want to manage a tag cloud e.g.
metadataMa:
tags: one,tow,four

..and i want mathc the instance if any of the tags is "four"

Feign compatibility

Hello,

I want to use your module with Feign.
Indeed, I have implemented my feign client thanks the @FeignClient annotation :

@FeignClient(name = "Account")
public interface MyService {
...
}

I want to use the Eureka metadata to filter the service which is called by Feign.

I tried to implement the "RequestInterceptor" interface but I don't have the serviceID which is called.

Do you have an idea ?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.