zuul-trie-matcher-spring-cloud-starter

Spring Cloud Netflix Zuul Trie Matcher

License

License

Categories

Categories

Zuul Application Layer Libs Distributed Applications
GroupId

GroupId

io.jmnarloch
ArtifactId

ArtifactId

zuul-trie-matcher-spring-cloud-starter
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

zuul-trie-matcher-spring-cloud-starter
Spring Cloud Netflix Zuul Trie Matcher
Project URL

Project URL

https://github.com/jmnarloch/zuul-trie-matcher-spring-cloud-starter
Source Code Management

Source Code Management

https://github.com/jmnarloch/zuul-trie-matcher-spring-cloud-starter.git

Download zuul-trie-matcher-spring-cloud-starter

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-configuration-processor Optional jar 1.2.5.RELEASE
net.sf.trove4j : trove4j jar 3.0.3
org.springframework.cloud : spring-cloud-starter-zuul 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 Zuul Trie route matcher

A Spring Cloud Trie route matcher

Build Status Coverage Status

Features

Extends the Spring Cloud's ProxyRouteLocator with configurable matching strategy. The provided implementation allows to register a Trie tree for matching the routes.

Setup

Add the Spring Cloud starter to your project:

<dependency>
  <groupId>io.jmnarloch</groupId>
  <artifactId>zuul-trie-matcher-spring-cloud-starter</artifactId>
  <version>1.2.0</version>
</dependency>

Enable the Zuul proxy with @EnableZuulProxyMatcher - use this annotation as a replacement for standard @EnableZuulProxy, the only requirement to use this component is to register a concrete bean of type RouteMatcher

@EnableZuulProxyMatcher
@SpringBootApplication
public static class Application {

    @Bean
    public RouteMatcher routeMatcher() {
        return new TrieRouteMatcher(() -> Tries.newCharHashMapTrie());
    }
}

Except for that everything is generally the same as when used with standard Zuul proxy.

Implementation details

The Trie is a R way tree that is designed for efficient string searches, perfectly fitting for use cases like Zuul route path matching. For most effective use the Trie is being build on application context refresh and used for queries afterwards.

At this moment this component defines three different implementation of the Trie, all of which differs slightly in performance, but far most with the memory consumption.

The available Trie implementations are:

  • CharArrayTrie
  • HashMapTrie
  • CharHashMapTrie - that uses Trove TCharObjectHashMap

Performance characteristics

The standard implementation of ProxyRouteLocator iterates over every ZuulProperties.ZuulRoute in order to find the first one matching the request URI. If we denote N - as number of routes and M as the maximum path length then we can say that finding the path takes O(NM) time in worst case.

The proposed alternative will replace this path finding by performing prefix search on the Trie tree, with running time of O(M) in worst case, the performance gains are made in exchange of extra memory usage.

Also the side effect of using the Trie is that it allows to define overlapping paths for instance:

  • /uaa/**
  • /uaa/account/**

As already stated the standard implementation would chose either of those paths depending on the order they have been defined in properties file, the Trie tree in contrary would find the best matching route i.e. for path /uaa/authorize, /uaa/** would be used and for /uaa/account/j.doe, /uaa/account/** is going to be matched.

Plans for version 2.x

The Spring Cloud 1.1 will include some minimal integration for this project, allowing to remove unnecessary parts like the @EnableZuulProxyMatcher - that is only there to import the required classes, besides that I've also decided to extract the Trie implementation into separate component and continue the development separately: https://github.com/jmnarloch/trie

License

Apache 2.0

Versions

Version
1.2.0
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0