Giter Site home page Giter Site logo

sentinel-zuul-sample's Introduction

sentinel-zuul-sample

Zuul does not provide rateLimit function, If use SentinelRibbonFilter route filter. it wrapped by Hystrix Command. so only provide Service level circuit protect.

Sentinel can provide ServiceId level and API Path level flow control for zuul gateway service. This is simple project for alibaba/Sentinel spring cloud zuul integration sample.

Note: this project is for zuul 1.

Modules

eureka-server:

module used for discovery server. when service restart. it should be restart.

  • EurekaServiceApplication: runs eureka service on port 8671. access by http://localhost:8761/

zuul-backend

backend service after gateway. consist of two application book and coke.

  • CokeApplication: hosts a /coke ,/except service on port 9082
  • BookApplication: hosts a /coke ,/except service with different implementation on port 9081

zuul-gateway

zuul gateway application.

  • GatewayApplication runs zuul on port 8990.

How to run

run as spring boot application

curl -i localhost:8990/coke/coke

curl -i localhost:8990/coke/block

curl -i localhost:8990/coke/except

curl -i localhost:8990/book/coke

Integration Sentinel Filter

  • SentinelRibbonFilter: extends RibbonRoutingFilter. override run method which add sentinel check. this project also enable Hystrix Circuit.
  • SentinelOkHttpRoutingFilter: use okHttp3 as custom routing http client. and without Hystrix bind.

By default use SentinelOkHttpRoutingFilter as route filter:

 // disable filter can be set here.
 public static void main(String[] args) {
        new SpringApplicationBuilder(GatewayApplication.class)
                .properties("zuul.RibbonRoutingFilter.route.disable=true",
                        "zuul.SentinelRibbonFilter.route.disable=true")
                .run(args);
    }
    

Filters create structure like:

1. add vm config: -Dcsp.sentinel.api.port=18990

2. curl http://localhost:18990/tree?type=root

EntranceNode: machine-root(t:3 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
-EntranceNode: coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
--coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
---/coke/coke(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
-EntranceNode: sentinel_default_context(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
-EntranceNode: book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
--book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
---/book/coke(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)


book and coke are serviceId.

---/book/coke is api path.

Integration with Sentinel DashBord

  1. start Sentinel DashBord.

  2. add vm property to zuul-gateway. -Dcsp.sentinel.dashboard.server=localhost:8088 -Dcsp.sentinel.api.port=18990.

  3. Sentinel has full rule config features. see Dynamic-Rule-Configuration

Fallback

Zuul provide FallbackProvider to cope with fall back logic.

sentinel-zuul-sample's People

Contributors

tigermoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar techzealot avatar lxiol avatar  avatar 大龙 avatar wxmimperio avatar Carpenter Lee avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

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.